Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes Reading a XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Reading a XML file" Watch "Reading a XML file" New topic
Author

Reading a XML file

arnav prateek
Greenhorn

Joined: Apr 06, 2006
Posts: 17
Hi,

I have a complex XML file to read,

Actual XML file looks like this:
<LDEGER>
<DAYPROFIT>
<DAY>
<NAME>Monday</NAME>
</DAY>1234
<DAY>
<NAME>TuesDay</NAME>
</DAY>1002
</DAYPROFIT>
</LEDGER>

Here DAY tag can appear multiple times and if you have noticed 1234 and 1002 are appearing just after each closing tag of DAY..
I am able to read Name tags but unable to read 1234 and 1002....values using SAX and dom parser...

Can somebody will help in reading this file?

Thanks in Advance.

Regards
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
I'm not sure how you're parsing but if you use the Java API for XML (JAX) and implement the org.xml.sax.ContentHandler interface you should get a call to the characters() method with the text supplied as an array of chars after a call to endElement() passing the name of the "DAY" elements. You should also be able to get the info using javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlSource) and traveresing the returned Document instance. (I noticed a mistake in your example XML, the opening tag for LEDGER is misspelled. Maybe that's a problem?)


Holla at me...<br /><a href="http://codeforfun.wordpress.com" target="_blank" rel="nofollow">http://codeforfun.wordpress.com</a>
 
wood burning stoves
 
subject: Reading a XML file