[Expat-discuss] Terminating expat - idea

Karl Waclawek karl at waclawek.net
Thu Mar 20 15:58:08 EST 2003



> Hi,
> i'd like just share idea of how to terminate expar processing
> for any reason. This question appears periodically here (most
> asked...), the logical answer is 'use exception in C++/Delphi
> or setjmp/longjmp in C', which is - of course - ok. However
> i guess for those who're looking for platform/compiler/etc
> independent and a clear way (or are afraid of those mysterious
> jmps ;-) the following way could be acceptable
> (in scope of C language):
> 
> Create a struct, for example:
> 
> struct _XData
> {
>   int  err;                  // my own error number
>   int  errln;                // on which line
>   char errtxt[MAX_ERR_SIZE]; // optional additional info
> ...
> }; // there is some missing, i know ;-)
> typedef struct _XData XData;
> 
> and use it as userData. Main parsing loop:
> 
> ...
> XData x_data;
> x_data.err = 0;
> ...
> XML_SetUserData(parser, &x_data);
> ...
> do
> {
>   // get data
>   if(XML_Parse(parser, Buff, len, done) == XML_STATUS_ERROR)
>     'handle parser error & bye
>   else
>     if(x_data.err > 0)
>       'handle user error & bye or whatever
> } while(are_there_some_data);

If I understand this correctly you can only stop parsing on return from
XML_Parse (before the next buffer is processed). That means, 
for large buffers, and especially for documents smaller than the buffer size,
this won't really be satisfying.

We are actually working on a combined Push/Pull API for Expat versions > 2.0,
which will have return codes for the handlers, as it stands right now. Certain
return codes will cause Expat to stop parsing. 

Karl






More information about the Expat-discuss mailing list