[英]how to get off with the libxml2 error messages
我想使用libxml2 lib来解析我的xml文件。 现在,当我有一些糟糕的xml文件时,lib本身正在打印大错误消息。
下面是一些示例代码
reader = xmlReaderForFile(filename, NULL, 0);
if (reader != NULL) {
ret = xmlTextReaderRead(reader);
while (ret == 1) {
printf("_________________________________\n");
processNode(reader);
ret = xmlTextReaderRead(reader);
printf("_________________________________\n");
}
xmlFreeTextReader(reader);
if (ret != 0) {
fprintf(stderr, "%s : failed to parse\n", filename);
}
}
在上面的例子中,如果我有错误的xml文件,我会得到这样的错误
my.xml:4: parser error : attributes construct error
include type="text"this is text. this might be excluded in the next occurrence
my.xml:4: parser error : Couldn't find end of Start Tag include
include type="text"this is text. this might be excluded in the next occurrence
my.xml : failed to parse
相反,我只是想回复一些错误。 和这个丑陋的lib消息一起下车。
我该怎么办 ?
xmlReaderForFile(filename, NULL, 0);
的最后一个参数xmlReaderForFile(filename, NULL, 0);
是一组选项标志。 阅读这些标志的文档 ,我看到有两个选项可能需要设置: XML_PARSE_NOERROR
和XML_PARSE_NOWARNING
。 请注意,我还没有尝试过任何这个,我只是用Google搜索libxml2和xmlReaderForFile。
你需要或像这样的标志:
reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.