3

I have one HTML file and what I have to do is to store this file into some array or big string and then do the required modifications. I have to include some Javascripts and some other elements with attributes and also have to eliminate some of them. Can anyone plaese help me out in doing this. Thanking you!

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-type" content="text/html;  charset=utf-8" />  
<title>eXe</title>  
<style type="text/css">  
@import url(base.css);  
@import url(content.css);  
</style>  
<script type="text/javascript" src="common.js"></script>
<!--HERE I NEED TO INCLUDE 3 MORE JAVASCRIPTS-->  
</head>  
<body>  
<div id="outer">  
<div id="main">  
<div id="nodeDecoration">  
<p id="nodeTitle">  
Part 1</p>  
</div>  
<div class="TrueFalseIdevice" id="id12">  
<script type="text/javascript" src="common.js"></script>  
<!--THIS JAVASCRIPT HAS TO BE ELIMINATED-->  
<script type="text/javascript" src="libot_drag.js"></script>  
<div class="iDevice emphasis1">  
<img alt="" class="iDevice_icon" src="icon_question.gif" />  
<span class="iDeviceTitle">True-False Question</span><br/>  
<div class="iDevice_inner">  
<div id="ta12_16" class="block" style="display:block">  

</div><div class="question">  
<br/><br/><div id="taquestion0b12" class="block" style="display:block">1><span style="color: #000000; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline ! important; float: none"> SQL Stands for Structure Query Language?</span>   

<!--THIS ONCLICK EVENT HAS TO BE REMOVED-->  
</div><br/>True <input type="radio" name="option0b12" id="true0b12" onclick="getFeedback(0,2,'0b12','truefalse')"/>   
False <input type="radio" name="option0b12" id="false0b12" onclick="getFeedback(1,2,'0b12','truefalse')"/>  
<div id="s0b0b12" style="color: rgb(0, 51, 204);display: none;" even_steven="18">Correct! </div>  
<div id="s1b0b12" style="color: rgb(0, 51, 204);display: none;" even_steven="19">Incorrect! </div>  
<div id="sfbk0b12" style="color: rgb(0, 51, 204);display: none;"><div id="tafeedback0b12" class="block" style="display:block">  
<!--HERE I NEED TO INCLUDE A SUBMIT BUTTON-->
</div></div>  
</div>  
</div>  
</div>  
</body></html> 
1
  • @Genzer Hi, I have tried to read the file by using BufferedReader but I don't know how to add the required elements into it. I tried it by seeing this example- stackoverflow.com/questions/8563294/… Commented Jul 14, 2012 at 19:16

2 Answers 2

5

Java already has a parser, called DOM that could help you. You could use something like this:

File theXML = new File("C:\\path\\to\\file.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(theXML);
doc.getDocumentElement().normalize();

If you've ever used JavaScript DOM, you should know what to do now, use doc.getElementsByTagName or the like. If you don't, check out the oracle tutorial

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the suggestions. I'll try in this way now.
0

You can use this way to read your html (into a String). After that, your task is actualy to do some String splitting, replacing and inserting, and, finally, writing it all to the html file on your HDD using a simiar method as you read it from the HDD.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.