Howto handle libxml2 parser errors

陌路散爱 提交于 2019-12-25 02:52:33

问题


I have to use xsd (schema) validation with libxml2, I can set a callback for error-handling, for the schema-validation errors, using: 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.


回答1:


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



来源:https://stackoverflow.com/questions/15365451/howto-handle-libxml2-parser-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!