Re: [xml] stopping parsing



On Fri, Oct 31, 2003 at 10:09:13AM +1100, Malcolm Tredinnick wrote:
On Fri, 2003-10-31 at 09:50, Graham Bennett wrote:
Hi all,

What's the best way of stopping the parser from the SAX interface?

My situation is this:  I'm doing 'partial' parsing of a document which
involves stopping when a certain element is reached and not doing any
more processing.  My initial solution was to NULL out all of my
callbacks in the SAX handler so that the parser runs through to the end
without my code receiving any more events.  This seems to work, but it
would be nice to be able to stop the parser in its tracks rather than
letting it finish the document.

I looked at xmlStopParser, but I will tend to call this when I hit a
start element, and the parser will give me errors back saying that it
hit the end of the data before seeing the end element.

Notwithstanding Daniel's offer to include some extract code in libxml to
help with this, my current solution to this problem is to set a variable
within my data structure to indicate "I am shutting down". I set this

  the parser context has a ctxt->disableSAX field used to block further
callbacks, it's not set set in xmlStopParser and is a trivial way of doing
so. To shutdown errors too, the very same variable could simply be checked
in the error routines.
  So there are simple ways to do this without change in the client
code. The enclosed patch implements this, I will commit this as soon as I
can check there is no negative side-effect.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

Attachment: stop.patch
Description: Text document



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]