Howto handle libxml2 parser errors

2019-09-16 06:34发布

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.

标签: c libxml2
1条回答
啃猪蹄的小仙女
2楼-- · 2019-09-16 06:57

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

查看更多
登录 后发表回答