I'm trying to parse a never-ending xml stream that looks like this:
<outer>
<foo>footext</foo>
<bar>bartext</bar>
</outer>
<outer>
<foo>footext</foo>
<bar>bartext</bar>
</outer>
<outer>
<foo>footext</foo>
<bar>bartext</bar>
</outer>
...
I've got my SAXParser set up:
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
SAXParser parser = factory.newSAXParser();
And I can call it with an InputStream and my implementation of Defaulthandler easily enough:
parser.parse(theInputStream, myHandler);
The problem is that I need the parser.parse to actually return after it hits a </outer>
end tag so that I can return the object I parsed out of the xml. The reason for this is that my parsing code (in a class called XMLParser) is called in a loop like this:
while(condition) {
Object o = xmlParser.getNextObject();
... do something with the object ...
}
Is it possible to make a SAXParser return from a parse(InputStream, DefaultHandler) call before it has read the entirety of the available stream?