In my software, I use libxml2 to manipulate (obviously) XML data structures. I mainly use XSD schema validation and so far, it works well.
When the data structure input by the client doesn’t match the XSD schema, libxml2 output some debug messages to the console.
Here is an example:
/data/file_name:5230: parser error : StartTag: invalid element name
<
^
While those strings are useful for debugging purposes, I don’t want them to appear and polute the console output in the final app. So far, I couldn’t find an official way of doing this.Though, i do have one method of modifying the library itself,but i’m looking for a library configuration which does that i.e, without modifying the code.
Do you know how to suppress the debug output or (even better) to redirect it to a custom function ?
Peace & Regards.
There is a callback mechanism for outputting warnings and errors the way you want.
As said in the API documentation, xmlSchemaSetParserErrors()
Set the callback functions used to handle errors for a validation context.You need to write two callback functions with respect to defined signature :
An example could be :
Then just call
xmlSchemaSetValidErrors(valid_ctxt_ptr, (xmlSchemaValidityErrorFunc) err, (xmlSchemaValidityWarningFunc) warn, ctx);before calling