问题
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