[lxml-dev] Verbose validation error messages?
Hi, I'm interested in using lxml's validation capabilities. Specifically, I want to validate XML documents according to a RELAX-NG schema. What seems to be missing from the lxml API is the ability to receive verbose validation error messages: The 'validate' method of the RelaxNG class just returns 0 or 1 depending on whether the document validates. The libxml2 library is able to report much more information, such as the exact line number where the validation fails and the reason (as can be seen when using xmllib2's 'xmllint' tool). Are there any plans to add support for this to lxml? It seems like throwing an exception when the validation fails, and add the information to the exception object, would be a clean way to handle this. -- Gavrie
Gavrie Philipson wrote:
I'm interested in using lxml's validation capabilities. Specifically, I want to validate XML documents according to a RELAX-NG schema.
What seems to be missing from the lxml API is the ability to receive verbose validation error messages: The 'validate' method of the RelaxNG class just returns 0 or 1 depending on whether the document validates. The libxml2 library is able to report much more information, such as the exact line number where the validation fails and the reason (as can be seen when using xmllib2's 'xmllint' tool).
Are there any plans to add support for this to lxml? It seems like throwing an exception when the validation fails, and add the information to the exception object, would be a clean way to handle this.
Yes, there are plans to add support for this, and I had something with exceptions in mind as well myself. Better error reporting is one of the bigger items on the lxml todo list -- we have similar cases of too little information in the case of XML parser errors and XSLT parsing, for instance. Hooking things correctly into libxml2's way of error handling is however a significant task, as it's a rather involved API. I do it wrong now actually -- if you run lxml in a separate thread you actually *do* see the messages spewed out to stderr (or stdout, I am not sure), as my suppression of messages isn't perfect and in fact needs to repeated for each thread. I'd very much like to have this fixed and the error messages correctly collected, though. So, while there are plans, I do not see me working much on this in the forseeable future. Help and/or cash can of course speed this up. :) Regards, Martijn
participants (2)
-
Gavrie Philipson
-
Martijn Faassen