[jdom-interest] How to kill a parser - nicely

Attila Szegedi szegedia at freemail.hu
Tue Aug 14 10:57:09 PDT 2001


Throw a SAXParseException. This sounds rude, but in fact it is not that
much. While parsing XML, depending on the implementation of the parser you
use, your handler might be called with a very-very deep call stack.

If there were a "nice" way (say, some flag you can set through a
hypothetical stop() method on a Parser or XMLReader) the parser code would
have to contain checks of that flag all around the place - it would make it
messy and error-prone.

In light of this, it's perfectly acceptable to stop parsing by throwing a
SAXParseException. Just remember to catch it at the point you called
Parser.parse().

Attila.

----- Original Message -----
From: "Dennis Fuglsang" <dfuglsang at metamatrix.com>
To: <jdom-interest at jdom.org>
Sent: 2001. augusztus 13. 20:31
Subject: [jdom-interest] How to kill a parser - nicely


> The answer to this question may be simple, and I hope it is, but is there
a
> means to stop/terminate the parsing operation before it has completed
> reading the entire document? I need to read only the header portion of a
> number of potentially large documents and I would like to do it in near
> constant time (independent of the document size).  I implemented my own
SAX
> ContentHandler in the hope that after reading the header information I
could
> then close the parser.  Well I have not discovered any "nice" way of doing
> this yet.  I welcome any suggestions.  Thanks.
>
> dfuglsang at metamatrix.com
>




More information about the jdom-interest mailing list