[xml] xmlGenericErrorFunc error handling



Other people on this list pointed out that if you're creating your own error
handler, you have to deal with your error handler being called multiple
times for a single error.  So here is my question:

How can I safely gather the entire error message and output it to a log file
in one line?

What I have done to work around this so far is to store all the pieces of
the error message in a static buffer (static char *) until I receive the
piece (string) that ends in a newline character, then I copy the buffer to
my logging function (also prepending "libxml:" to it).  Therefore, I'm
making the assumption that I will eventually get a string that ends in a
newline character.  I'm not sure if that's a safe assumption.

Jason

---
Registering the callback:
xmlSetGenericErrorFunc(NULL, (xmlGenericErrorFunc)libxml_log);
Defining the callback function:
void libxml_log(void *ctx, const char *msg, ...) { }




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