[英]Is there any way to handle errors in libxml sax parsing?
由于某种原因,我必须在我的C ++代码中使用libxml,并且我的程序正在使用sax方法解析xml文件。是否有任何方法可以处理解析中的错误或异常?
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);
}
And register them using xmlSetGenericErrorFunc
and xmlSetStructuredErrorFunc
. 并使用
xmlSetGenericErrorFunc
和xmlSetStructuredErrorFunc
注册它们。
Example of registration without context : 没有上下文的注册示例:
xmlSetGenericErrorFunc(NULL, my_fatalError);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.