lxml.etree.iterparse फ़ंक्शन का उपयोग करके निम्न पायथन फ़ाइल को पार्स करने का प्रयास कर रहा है।पायथन के साथ बड़ी एक्सएमएल फ़ाइल को पार्सिंग - etree.parse त्रुटि
"sampleoutput.xml"
<item>
<title>Item 1</title>
<desc>Description 1</desc>
</item>
<item>
<title>Item 2</title>
<desc>Description 2</desc>
</item>
मैं etree.iterparse (myFile) कहते हैं मैं myFile = खुला ("/ उपयोगकर्ताओं/eric/डेस्कटॉप/wikipedia_map से पहले किया था से Parsing Large XML file with Python lxml and Iterparse
कोड की कोशिश की /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
कोई विचार? धन्यवाद!
यह हो सकता है कि आपकी XML फ़ाइल दूषित है:
निम्नलिखित दस्तावेज़ अपने मौजूदा कोड के साथ सही परिणाम का उत्पादन? इसमें कोई ' Xml' टैग या रूट तत्व नहीं है। – C0deH4cker
मुझे एलएक्सएमएल नहीं पता, लेकिन आपका उदाहरण वैध एक्सएमएल नहीं है। एक एक्सएमएल दस्तावेज़ में एक रूट तत्व होना चाहिए। आपका नहीं है –
आपको रूट तत्व की आवश्यकता नहीं है, न केवल बाल नोड्स। – pinkdawn