Hello! Tell me please is it possible to break the process of parsing? I.e. exit this loop not reaching the end of document and corresponding event "endDocument" ?
+3
A:
Throw an exception in the handler and catch it in the code block where you started parsing:
try {
...
xmlReader.parse();
} catch (SAXException e) {
if (e.Cause instanceof BreakParsingException) {
// we have broken the parsing process
....
}
}
And in your DocumentHandler:
public void startElement(String namespaceURI,
String localName,
String qName,
Attributes atts)
throws SAXException {
// ...
throw new SAXException(new BreakParsingException());
}
chiccodoro
2010-06-03 08:29:38
+1
A:
You have to throw a SAXException. In order to distiguish it from regular errors I would subclass it with my own Exception class
Peter Tillemans
2010-06-03 08:34:13
+1
A:
Same as this question http://stackoverflow.com/questions/1345293/how-to-stop-parsing-xml-document-with-sax-at-any-time
Brian
2010-06-03 08:38:23