From andrelsm at iname.com Wed Oct 4 06:17:37 2006 From: andrelsm at iname.com (Andre Luis Monteiro) Date: Tue, 03 Oct 2006 23:17:37 -0500 Subject: [Expat-discuss] How to stop parsing a block at a appl-level error Message-ID: <20061004041737.3DF301CE304@ws1-6.us4.outblaze.com> Hi, I'm one more Expat newbie just amazed by the conceptual simplicity and roubustness of this lib / API. Great work! I'm building a C parser state machine on top of Expat, targeting config XML files. It was quite easy to code, and it's working fine and fast. But I'm not satisfied with it's error handling, since the "semantic errors" -- XML structure errors or application-level errors derived from config actions -- must be "postponed" to the next XML document block to parse; I have not found a (fancy) manner to handle them as soon as they are found, stopping further parsing and returning the XML_Parser info (like line number and column etc.). I didn't understand why the XML handler typedefs (like XML_StartElementHandler) do not declare a return value that could signal "user errors", in such a way that applications (XML parsers) could tell Expat to "get away with the shit" in a simple manner. Please explain the reasons why, ok? I'm a novice, just learning XML, SAX, Expat. Moreover, please tell me how to stop the parsing and return as soon as an application-level error could be found (in a XML_StartElementHandler or a XML_EndElementHandler, for ex.). regards Andr? Lu?s PS: sorry for my bad English... -- ___________________________________________________ Play 100s of games for FREE! http://games.mail.com From karl at waclawek.net Wed Oct 4 21:20:24 2006 From: karl at waclawek.net (Karl Waclawek) Date: Wed, 04 Oct 2006 15:20:24 -0400 Subject: [Expat-discuss] How to stop parsing a block at a appl-level error In-Reply-To: <20061004041737.3DF301CE304@ws1-6.us4.outblaze.com> References: <20061004041737.3DF301CE304@ws1-6.us4.outblaze.com> Message-ID: <45240978.8080902@waclawek.net> Andre Luis Monteiro wrote: > Hi, > > I'm one more Expat newbie just amazed by the conceptual simplicity and roubustness of this lib / API. Great work! > > I'm building a C parser state machine on top of Expat, targeting config XML files. It was quite easy to code, and it's working fine and fast. > > But I'm not satisfied with it's error handling, since the "semantic errors" -- XML structure errors or application-level errors derived from config actions -- must be "postponed" to the next XML document block to parse; I have not found a (fancy) manner to handle them as soon as they are found, stopping further parsing and returning the XML_Parser info (like line number and column etc.). > Have a look at the XML_StopParser and related functions. > I didn't understand why the XML handler typedefs (like XML_StartElementHandler) do not declare a return value that could signal "user errors", in such a way that applications (XML parsers) could tell Expat to "get away with the shit" in a simple manner. Please explain the reasons why, ok? I'm a novice, just learning XML, SAX, Expat. > Historical reasons of backward compatibility. If there is ever an Expat 3.0 line of versions, such a return value would likely be added. > Moreover, please tell me how to stop the parsing and return as soon as an application-level error could be found (in a XML_StartElementHandler or a XML_EndElementHandler, for ex.). > See above. Karl From kumar_qnx at yahoo.com Tue Oct 10 18:30:06 2006 From: kumar_qnx at yahoo.com (kumar qnx) Date: Tue, 10 Oct 2006 09:30:06 -0700 (PDT) Subject: [Expat-discuss] Return Types for XmlParserCreate Message-ID: <20061010163006.48569.qmail@web55001.mail.re4.yahoo.com> Hi, I would like to know what are the return types for XML_ParserCreate, i could not find it in the documentation. regards, Pavan. --------------------------------- Do you Yahoo!? Get on board. You're invited to try the new Yahoo! Mail. From andrelsm at iname.com Tue Oct 10 19:27:19 2006 From: andrelsm at iname.com (Andre Luis Monteiro) Date: Tue, 10 Oct 2006 12:27:19 -0500 Subject: [Expat-discuss] Return Types for XmlParserCreate Message-ID: <20061010172724.8EFC01024D@ws1-3.us4.outblaze.com> Hi In expat.h we have: struct XML_ParserStruct; typedef struct XML_ParserStruct *XML_Parser; ... /* Constructs a new parser; encoding is the encoding specified by the external protocol or NULL if there is none specified. */ XMLPARSEAPI(XML_Parser) XML_ParserCreate(const XML_Char *encoding); (for to understand XMLPARSEAPI, take a look at expat_external.h). XML_ParserCreate() returns a pointer to a XML_Parser instance, or NULL if it fails. regards Andr? Lu?s > ----- Original Message ----- > From: "kumar qnx" > To: expat-discuss at libexpat.org > Subject: [Expat-discuss] Return Types for XmlParserCreate > Date: Tue, 10 Oct 2006 09:30:06 -0700 (PDT) > > > Hi, > > I would like to know what are the return types for XML_ParserCreate, i > could not find it in the documentation. > > regards, > > Pavan. > > > --------------------------------- > Do you Yahoo!? > Get on board. You're invited to try the new Yahoo! Mail. > _______________________________________________ > Expat-discuss mailing list > Expat-discuss at libexpat.org > http://mail.libexpat.org/mailman/listinfo/expat-discuss > -- ___________________________________________________ Play 100s of games for FREE! http://games.mail.com From kumar_qnx at yahoo.com Tue Oct 10 20:43:31 2006 From: kumar_qnx at yahoo.com (kumar qnx) Date: Tue, 10 Oct 2006 11:43:31 -0700 (PDT) Subject: [Expat-discuss] How to stop parsing a block at a appl-level error In-Reply-To: <45240978.8080902@waclawek.net> Message-ID: <20061010184331.4150.qmail@web55004.mail.re4.yahoo.com> 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. From andrelsm at iname.com Wed Oct 11 18:10:04 2006 From: andrelsm at iname.com (Andre Luis Monteiro) Date: Wed, 11 Oct 2006 11:10:04 -0500 Subject: [Expat-discuss] How to stop parsing a block at a appl-level error Message-ID: <20061011161018.97BA51BF281@ws1-1.us4.outblaze.com> 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" > To: "Karl Waclawek" , 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 From andrelsm at iname.com Wed Oct 11 18:10:52 2006 From: andrelsm at iname.com (Andre Luis Monteiro) Date: Wed, 11 Oct 2006 11:10:52 -0500 Subject: [Expat-discuss] How to stop parsing a block at a appl-level error Message-ID: <20061011161053.BD6F81CE304@ws1-6.us4.outblaze.com> 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" > To: "Karl Waclawek" , 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 From andrelsm at iname.com Wed Oct 25 02:38:37 2006 From: andrelsm at iname.com (Andre Luis Monteiro) Date: Tue, 24 Oct 2006 19:38:37 -0500 Subject: [Expat-discuss] non-parsed data (CDATA) Message-ID: <20061025003839.B04D21BF287@ws1-1.us4.outblaze.com> Hi how does Expat handle non-parsed data? How to parse an XML element like this: We need something like: to get the CData section handlers working? regards Andr? Lu?s -- Search for products and services at: http://search.mail.com From marco.forberg at gmx.net Wed Oct 25 08:26:48 2006 From: marco.forberg at gmx.net (Marco Forberg) Date: Wed, 25 Oct 2006 08:26:48 +0200 Subject: [Expat-discuss] non-parsed data (CDATA) In-Reply-To: <20061025003839.B04D21BF287@ws1-1.us4.outblaze.com> Message-ID: <20061025062359.031851E4007@bag.python.org> Replace the < with the correct entity < The data inside the tags is handled by the function set by SetCharacterDataHandler. But rememvber: The text might be spread accross severak calls to the character data handler Your xml should look like this: -----Urspr?ngliche Nachricht----- Von: expat-discuss-bounces at libexpat.org [mailto:expat-discuss-bounces at libexpat.org] Im Auftrag von Andre Luis Monteiro Gesendet: Mittwoch, 25. Oktober 2006 02:39 An: expat-discuss at libexpat.org Betreff: [Expat-discuss] non-parsed data (CDATA) Hi how does Expat handle non-parsed data? How to parse an XML element like this: We need something like: to get the CData section handlers working? regards Andr? Lu?s -- Search for products and services at: http://search.mail.com _______________________________________________ Expat-discuss mailing list Expat-discuss at libexpat.org http://mail.libexpat.org/mailman/listinfo/expat-discuss