我尝试使用lxml验证大约100万行的xml文件.这是我的代码. import codecsimport lxml.etree as ETxsd_file = codecs.open(r'test.xsd', 'rb', 'utf-8')xml_file = codecs.open(r'test.xml', 'rb', 'utf-8')xmlschema_doc = ET.parse(xsd_fi
import codecs import lxml.etree as ET xsd_file = codecs.open(r'test.xsd', 'rb', 'utf-8') xml_file = codecs.open(r'test.xml', 'rb', 'utf-8') xmlschema_doc = ET.parse(xsd_file) xmlschema = ET.XMLSchema(xmlschema_doc) doc = ET.parse(xml_file) print (xmlschema.error_log.filter_from_errors())
但是如果错误的行超过65535,我发现输出总是显示“65535:0”.也就是说,
file:///C:test.xml:65535:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'word': Missing child element(s). file:///C:test.xml:65535:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'word': Missing child element(s). file:///C:test.xml:65535:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'word': Missing child element(s).
所以我无法确定上述行的位置.有什么解决方案吗?
这似乎是 bug in libXML, not in LXML itself persay,自2006年以来一直存在.由于向后兼容性问题,它似乎无法轻易修复.