5GB xml-fi上的模式验证

2024-09-27 09:33:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用以下方法验证一个5GB的大型XML文档:

from lxml.etree fromstring, XMLSchema

xmlschema = XMLSchema(xmlschema_doc)
root = fromstring(open(myfilepath).read())
xmlschema.assertValid(root)

但是,我开始遇到内存不足的错误:

OSError: [Errno 12] Cannot allocate memory

有没有一种“在运行中”的方法可以在xml中进行xsd验证,而不必将所有内容都加载到内存中?如果是,我该怎么做?你知道吗


Tags: 方法from文档readdocrootxmlopen

热门问题