尝试使用 lxml.etree.iterparse 函数解析以下 Python 文件。
“样本输出.xml”
<item>
<title>Item 1</title>
<desc>Description 1</desc>
</item>
<item>
<title>Item 2</title>
<desc>Description 2</desc>
</item>
我尝试了Parsing Large XML file with Python lxml and Iterparse中的代码
在 etree.iterparse(MYFILE) 调用之前,我做了 MYFILE = open("/Users/eric/Desktop/wikipedia_map/sampleoutput.xml","r")
但它出现了以下错误
Traceback (most recent call last):
File "/Users/eric/Documents/Programming/Eclipse_Workspace/wikipedia_mapper/testscraper.py", line 6, in <module>
for event, elem in context :
File "iterparse.pxi", line 491, in lxml.etree.iterparse.__next__ (src/lxml/lxml.etree.c:98565)
File "iterparse.pxi", line 543, in lxml.etree.iterparse._read_more_events (src/lxml/lxml.etree.c:99086)
File "parser.pxi", line 590, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:74712)
lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 5, column 1
有任何想法吗?谢谢你!