Re: [xml] SAX HTML still stuck.

On Thu, Oct 04, 2001 at 10:50:38AM -0700, Bill Moseley wrote:
Sorry for the boring and non-sexy questions, but I need help:

The parser is hanging when I try to abort processing.

I'd like to abort SAX parsing mid-document (in this case I'm aborting
right after </title>.  I set an abort flag in my user data, 
then on the next chunk read and bail out.  
    ctxt = htmlCreatePushParserCtxt(
        SAXHandler, &abort, buf, res, argv[1], 0);

    while ( !abort && (res = fread(buf, 1, 2048, f)) > 0)
        htmlParseChunk(ctxt, buf, res, 0);

    htmlParseChunk(ctxt, buf, 0, 1);

  why are you calling htmlParseChunk(ctxt, buf, 0, 1); if you have
aborted ??? 
  I can try to debug why in that strange condition the fact of saying
to the parser "I have nothing left to do" will break things, but basically
by overriding the endElement() callback completely without even calling it
after your own processing you clearly put the parser in a broken set.
  Basically, if you change the SAX callbacks, you're responsible to debug
possible problems at the parser level, especially if you're mixing DOM
building routines and your own ! Have a look at the endElement()
routing and please analyze what it means to not call it in a DOM building
parsing context. The current processed node is not popped up, and you're
messing the internal state DOM wise. 

  At the very least call endElement() from your replacement routine,

Sorry for the boring and non-sexy answer, but you need to debug your code
when you start messing with the SAX callbacks.


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml Gnome XML XSLT toolkit | Rpmfind RPM search engine

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