[Expat-discuss] Terminating expat - idea
Roskanuk Michal
Michal.Roskanuk at merlin.cz
Thu Mar 20 21:43:14 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);
Then check x_data.err at the beginning of every handler,
for example:
static void start(void *data, const char *el, const char **attr)
{
XData *px_data = (XData *) data;
if(px_data->err > 0)
return; // error occured somewhere, get out
and, of course fill out an error info whenever you
need followed by 'return' or 'goto CleanExit' or so.
This way makes code longer and a little bit slower,
but you're sure that everybody understands it and
it is totally portable (to every mind ;-).
Such workaround was posted already, however somebody
probably needs it roasted and with a soup, so i hope this helps.
Mike
- Get Started With Your Compaq, page 44:
- If your computer still doesn't work, ensure that it is
- plugged into an electrical outlet and try to turn it on.
More information about the Expat-discuss
mailing list