[lxml-dev] Details of XML Validation errors with lxml
Stefan Behnel
stefan_ml at behnel.de
Mon May 14 13:27:38 CEST 2007
Hi,
Eric Garin wrote:
> I've found some informations
> here http://codespeak.net/lxml/dev/api.html#error-handling-on-exceptions
and most likely also
http://codespeak.net/lxml/dev/validation.html
> Where Can I found the documentation API for error_log ?
The section in api.html which you mentioned above is already the main source.
You might also try 'help(etree)', which will tell you what fields there are in
the error log entries, or read the source code, class _LogEntry in
http://codespeak.net/svn/lxml/trunk/src/lxml/xmlerror.pxi
> I've found a bit by chance how to render the line number error but I
> would like for example to be abble to give to the users the offset (or
> position in line) where the error occur.
Sadly, this information is not provided by libxml2, so lxml can't provide it
either. Note also that the document might be constructed by hand (don't know
your application), in which case a line number would be meaningless already.
This is obviously a problem in 1-line XML documents, but a work around could
be to pretty print the document, parse it back in and then run the validation
a second time. This will give you a meaningful line number that you can then
use to provide the user with more context such as the surrounding tags.
Stefan
More information about the lxml-dev
mailing list