Re: [xml] stopping parsing



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
just prior to calling xmlStopParser(). Then my error handler checks this
and if it is in "shutting down" mode, does not process/report the error.

I guess this may not be appropriate for you, depending on how your data
structures are arranged. My general method have something hanging onto
the _private element of the ParserCtxt that I can add a "shutting_down"
field to, so I can let libxml haul the data pointer around for me.

It's is a bit (very?) hacky, but it seems to do the trick.

Cheers,
Malcolm




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