wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Extract data between two xml nodes with 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 "Extract data between two xml nodes with SAX Parser " Watch "Extract data between two xml nodes with SAX Parser " New topic
Author

Extract data between two xml nodes with SAX Parser

jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi All,

I have question about extracting xml data between two specific nodes with SAX Parser only.

Xml for your reference:


How can i get the data between <state id="product"></state> with all the child node. I dont want to use the dom xpath.I want to utilise the SAX parser.

Regards
Jatan
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 520
    
    3
How can i get the data between <state id="product"></state> with all the child node. I dont want to use the dom xpath.I want to utilise the SAX parser.

First you know how to get _all_ the data, whatever it means, using SAX parser, I suppose.

With that as the base, you impose conditions from within the method startElement() of the Content Handler... verifying [1] the qualified name being equal to "state", and that [2] there exists an attribute named "id" and that [3] the latter being of value "product". With all these conditions tested positive, you raise a flag or whatever and you start storing/displaying all the results in whatever format used in the way getting _all_ the data mentioned above with all methods including startElement() always checking the flag for the green light to store/display data.

And then, in the endElement() method you verify if the qname being "state" or not. If yes, reset the flag to stop storing/displaying data... If no, just leave the flag alone.

That is the general layout if not an oversimplified description.
 
GeeCON Prague 2014
 
subject: Extract data between two xml nodes with SAX Parser