[Expat-discuss] How to stop parsing a block at a appl-level error
Andre Luis Monteiro
andrelsm at iname.com
Wed Oct 11 18:10:04 CEST 2006
Hi,
I think in versions prior to 1.95.8 (when suspending / resuming were introduced) the only (right) thing to do is follow the Clark's recommendation: once an error is found, flag the error in the UserData structure, set all handlers to NULL and catch the error just after the XML_Parse (or ParseBuffer) call.
You should not call XML_ParserFree in a handler. This surely would "knockout" Expat and your application, since many resources are allocated and deallocated before and after handlers come into action. For ex., prior to invoke startElementHandler, the XMLParser creates a temp pool for to store attributes name and value pairs. Just after that, it frees the pool:
(excerpt from xmlparse.c)
...
#define tempPool (((Parser *)parser)->m_tempPool)
...
if (startElementHandler) {
...
result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
if (result)
return result;
startElementHandler(handlerArg, tag->name.str, (const XML_Char **)atts);
poolClear(&tempPool); /* what happens if XMLParserFree has already freed the XMLParser structure and the tempPool ? */
}
I think you should also avoid setjmp and lngjmp for to break parsing (this kind of hacking has been proposed some time ago). Beyond memory leak errors that could arise, you must be aware of thread context complexity. (I've written a lib and macros for to simulate try / catch in C and POSIX -- it store "jmp_buf bookmarks" stacks in pthreads TSD; it's working fine, but it is not yet avaliable as production code).
regards
André Luís
> ----- Original Message -----
> From: "kumar qnx" <kumar_qnx at yahoo.com>
> To: "Karl Waclawek" <karl at waclawek.net>, expat-discuss at libexpat.org
> Subject: Re: [Expat-discuss] How to stop parsing a block at a appl-level error
> Date: Tue, 10 Oct 2006 11:43:31 -0700 (PDT)
>
>
> Hi,
> I have a similar question to Luis, the version of libexpat i am using does
> not have XML_StopParser in it ( by the way i am using qnx 6.3 ,i checked the
> API and also the .so file).
> If i detect an error (or bad data ) in the xml and would like to stop
> parsing, can i use XML_ParseFree instead during the parsing operation ?
>
> regards,
>
> Pavan.
>
>
> ---------------------------------
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail.
> _______________________________________________
> Expat-discuss mailing list
> Expat-discuss at libexpat.org
> http://mail.libexpat.org/mailman/listinfo/expat-discuss
>
abraço
André Luís
--
___________________________________________________
Play 100s of games for FREE! http://games.mail.com
More information about the Expat-discuss
mailing list