[英]How to get the error position of xml file with lxml dtd.validate function in Python?
我想检查与sample.dtd关联的xml文件sample.xml的有效性。 但是我找不到错误位置。 我只是会收到错误消息。 我怎样才能做到这一点?
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())
尝试使用单个日志条目,而不是打印整个结果,例如
for error in dtd.error_log.filter_from_errors():
print(error.message)
print(error.line)
print(error.column)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.