如何处理libxml2解析器错误 [英] Howto handle libxml2 parser errors

查看:326
本文介绍了如何处理libxml2解析器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须对libxml2使用xsd(模式)验证,我可以使用xmlSchemaSetValidErrors()为模式验证错误设置回调以进行错误处理.

I have to use xsd (schema) validation with libxml2, I can set a callback for error-handling, for the schema-validation errors, using: xmlSchemaSetValidErrors().

但是在进行模式验证之前,我必须解析我的xml,以获得xmlDocPtr,例如与xmlParseMemory.但是:如果xml无效,该如何设置错误处理程序以获取这些错误? (我不希望将它们打印到stderr)我没有找到类似于xmlSchemaSetValidErrors的解析函数.

But before getting to the schema-validation, I have to parse my xml, to get a xmlDocPtr e.g. with xmlParseMemory. But: What if the xml is invalid, how do I set error-handlers for getting these errors? (I don't want them to be printed to stderr) I did not find a function similar to xmlSchemaSetValidErrors for the parsing functions.

推荐答案

您可以使用 xmlSetStructuredErrorFunc xmlSetGenericErrorFunc .这些设置了全局的错误回调,因为您已经注意到,此时将没有任何xmlDocPtr上下文.

You can use xmlSetStructuredErrorFunc and xmlSetGenericErrorFunc. These set error callbacks globally, because as you've noted, there won't be any xmlDocPtr context at this point.

http://www.xmlsoft.org/html/libxml-xmlerror.html

这篇关于如何处理libxml2解析器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆