Take the tour ×  This question already has an answer here:  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" ?  share|improve this question
Same as this question stackoverflow.com/questions/1345293/… – 
Brian Jun 3 '10 at 8:38 add comment  marked as duplicate by
Raedwald, Endoro, Emile, danodonovan, cwallenpoole Jun 5 at
15:44   3 Answers  up vote 8 down vote accepted  Throw an
exception in the handler and catch it in the code block where
you started parsing:  try { } 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());
share|improve this answer BTW: