Reputation: 1289
I want to check the validation of a xml file, sample.xml, associated with sample.dtd. But I can't get the error position. i just can get error message. How can I do that?
import lxml.etree as ET
import codecs
f = codecs.open('sample.dtd')
dtd = ET.DTD(f)
root = ET.parse('newace_JK.xml')
print(dtd.validate(root))
print(dtd.error_log.filter_from_errors())
Upvotes: 1
Views: 1043
Reputation: 28696
try using the individual log entries instead of printing the whole result, for example
for error in dtd.error_log.filter_from_errors():
print(error.message)
print(error.line)
print(error.column)
see http://lxml.de/api/lxml.etree._LogEntry-class.html
Upvotes: 1