我试图用python读取XML文件xml.etree但有时对于某些文件,我在解析文件时会出现内存错误。我的XML文件大小是912Mb,这个问题与文件大小有关吗?在
代码:from xml.etree import ElementTree
with open('F:\\Reports\\Logs\\AppPerfect_States\\TG1_GM\\Result_TG1_V16.xml', 'rt') as f1:
tree = ElementTree.parse(f1)
错误:
^{pr2}$
更新:
根据很多建议,我尝试了lxml
代码:from lxml import etree
context = etree.iterparse('F:\\Reports\\Logs\\AppPerfect_States\\TG1_GM\\Result_TG1_V16.xml',tag = "document")
for event, element in context:
for child in element:
print child.tag, child.text
element.clear()
错误:C:\Python27\python.exe "F:/Py Projects/V16_AUTO/test1/xmlparsingtest1.py"
Traceback (most recent call last):
File "F:/Py Projects/V16_AUTO/test1/xmlparsingtest1.py", line 3, in
for