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.
You can use
xmlSetStructuredErrorFunc
andxmlSetGenericErrorFunc
. 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