Reputation: 161
I have to use libxml in my c++ code, for some reason and my program is parsing xml files with sax method.Is there any way to handle errors or exceptions in parsing?thanks in advance.
Upvotes: 0
Views: 375
Reputation: 10688
You can write your own error handler like this :
static void my_error(void *user_data, const char *msg, ...) {
va_list args;
va_start(args, msg);
g_logv("XML", G_LOG_LEVEL_CRITICAL, msg, args);
va_end(args);
}
static void my_fatalError(void *user_data, const char *msg, ...) {
va_list args;
va_start(args, msg);
g_logv("XML", G_LOG_LEVEL_ERROR, msg, args);
va_end(args);
}
(example from here)
And register them using xmlSetGenericErrorFunc
and xmlSetStructuredErrorFunc
.
Example of registration without context :
xmlSetGenericErrorFunc(NULL, my_fatalError);
Upvotes: 1