aspose file tools*
The moose likes XML and Related Technologies and the fly likes reading the contents of an element using SAX parser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "reading the contents of an element using SAX parser" Watch "reading the contents of an element using SAX parser" New topic
Author

reading the contents of an element using SAX parser

Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
Hi,

I have an XML that could be nested, eg



i want to get the value of a particular element, eg the value of element B is


and the value of element C is "C1".
Also, i want to use SAX parser and not the DOM parser.

I was wondering if there is a library which uses SAX parser to accomplish this, instead of me writing a SAX parser.

Thank you

Rahul


Rahul Babbar
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18889
    
    8

You don't have to write a SAX parser. You just have to write a ContentHandler.

And no, there isn't a ContentHandler implementation available which searches for data in a C element which is the child of a B element which is the child of the root element which is an A. That's what you have to write. It isn't difficult, you just have to have your ContentHandler keep track of where it is in the document.
Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
Thanks Paul,

I wrote it up and it works...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading the contents of an element using SAX parser