<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:12pt"><DIV>Hi All,<BR><BR>I appears to have difficulty closing (possibly flushing it first) an XML file that was subsequently being parsed without success. The error generated is:<BR><BR><B>org.jdom.input.JDOMParseException: Error on line 23: The element type "form" must be terminated by the matching end-tag "</form>".</B></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif">
<DIV><STRONG></STRONG>
<DIV class=pad5x10><BR>Below is the code snippets of readData() to retrieve (HTML) data from a website, save it to a file, then convert to XML format before returning the new filename:<BR><CODE class="jive-code jive-java"><FONT color=navy><B></B></FONT></CODE></DIV>
<DIV class=pad5x10><CODE class="jive-code jive-java"><FONT color=navy><B>public</B></FONT> String readData() <FONT color=navy>{</FONT><BR> <BR> <FONT color=navy><B>try</B></FONT> <FONT color=navy>{</FONT><BR> URL url = <FONT color=navy><B>new</B></FONT> URL(<FONT color=red>"http://www.abc.com"</FONT>);<BR> URLConnection connection = url.openConnection(); <BR> InputStream isInHtml = url.openStream(); <FONT color=darkgreen>// throws an IOException </FONT><BR> disInHtml = <FONT color=navy><B>new</B></FONT> DataInputStream(<FONT color=navy><B>new</B></FONT> BufferedInputStream(isInHtml));
<BR> System.out.flush(); <BR> FileOutputStream fosOutHtml = <FONT color=navy><B>null</B></FONT>;<BR> fosOutHtml = <FONT color=navy><B>new</B></FONT> FileOutputStream(<FONT color=red>"C:\\Temp\\ABC.html"</FONT>);<BR> <FONT color=navy><B>int</B></FONT> oneChar, count=0;<BR> <FONT color=navy><B>while</B></FONT> ((oneChar=disInHtml.read()) != -1)<BR> fosOutHtml.write(oneChar);</CODE></DIV>
<DIV class=pad5x10><CODE class="jive-code jive-java"> }<BR> catch { ... }<BR> finally {<BR> isInHtml.close();<BR> disInHtml.close();<BR> fosOutHtml.flush(); // optional<BR> fosOutHtml.close();<BR> }<BR> <FONT color=navy>}</FONT><BR> <BR> <FONT color=navy><B>try</B></FONT> <FONT color=navy>{</FONT><BR> File fileInHtml = <FONT color=navy><B>new</B></FONT> File(<FONT color=red>"C:\\Temp\\ABC.html"</FONT>);<BR> FileReader frInHtml = <FONT color=navy><B>new</B></FONT>
FileReader(fileInHtml);<BR> BufferedReader brInHtml = <FONT color=navy><B>new</B></FONT> BufferedReader(frInHtml);<BR> String string = <FONT color=red>""</FONT>;<BR> <FONT color=navy><B>while</B></FONT> (brInHtml.ready())<BR> string += brInHtml.readLine() + <FONT color=red>"\n"</FONT>;<BR> fwOutXml = <FONT color=navy><B>new</B></FONT> FileWriter(<FONT color=red>"C:\\Temp\\ABC.xml"</FONT>);<BR> pwOutXml = <FONT color=navy><B>new</B></FONT> PrintWriter(fwOutXml);<BR> light_html2xml html2xml = <FONT color=navy><B>new</B></FONT>
light_html2xml();<BR> pwOutXml.print(html2xml.Html2Xml(string));</CODE></DIV>
<DIV class=pad5x10><CODE class="jive-code jive-java"> }<BR> catch { ... }<BR> finally {<BR> fwOutXml.close();<BR> pwOutXml.close();<BR> }<BR> <FONT color=navy><B>return</B></FONT> fileInHtml.getAbsolutePath();<BR><FONT color=navy>}</FONT><BR> <BR><FONT color=darkgreen>// parseData reads the XML file using the name returned by readData()</FONT><BR><FONT color=navy><B>public</B></FONT> <FONT color=navy><B>void</B></FONT> parseData(String XMLFilename)<BR><FONT color=navy>{</FONT><BR> <FONT color=navy><B>try</B></FONT> <BR> <FONT color=navy>{</FONT><BR> FileReader frInXml = <FONT color=navy><B>new</B></FONT> FileReader(FileName);<BR> BufferedReader brInXml =
<FONT color=navy><B>new</B></FONT> BufferedReader(frInXml);<BR> SAXBuilder saxBuilder = <FONT color=navy><B>new</B></FONT> SAXBuilder(<FONT color=red>"org.apache.xerces.parsers.SAXParser"</FONT>); <FONT color=darkgreen>// JDOMParseException generated.</FONT><BR> ....<BR><FONT color=navy>}</FONT><BR></DIV></CODE>
<DIV class=pad5x10>These codes would worked when they were in a single method but I have since placed some structure around them using a number methods.<BR><BR>This issue has risen in th past where I have been able to close the XML file prior to reading them again. However, I don't have a solution for it this time round.<BR><BR>I am running JDK 1.6.0_10, Netbeans 6.1, JDOM 1.1 on Windows XP platform.<BR><BR>Any assistance would be appreciated.<BR><BR>Many thanks,<BR><BR>Jack </DIV></DIV></DIV></DIV></DIV></DIV></DIV></DIV></div><br>
<hr size=1> Search 1000's of available singles in your area at the new Yahoo!7 Dating.
<a href="http://au.rd.yahoo.com/dating/mail/tagline1/*http://au.dating.yahoo.com/?cid=53151&pid=1011">Get Started</a>.</body></html>