Answer the question
In order to leave comments, you need to log in
Parsing XML with Python. How to solve the problem in LXML?
There is this code:
file_events = "1.xml"
f = open(file_events)
xml = f.read()
f.close()
tree = etree.parse(StringIO(xml))
tree = etree.parse(StringIO(xml))
File "lxml.etree.pyx", line 3427, in lxml.etree.parse (src\lxml\lxml.etree.c:79720)
File "parser.pxi", line 1799, in lxml.etree._parseDocument (src\lxml\lxml.etree.c:116138)
File "parser.pxi", line 1819, in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:116413)
File "parser.pxi", line 1707, in lxml.etree._parseDoc (src\lxml\lxml.etree.c:115063)
File "parser.pxi", line 1079, in lxml.etree._BaseParser._parseDoc (src\lxml\lxml.etree.c:109462)
File "parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src\lxml\lxml.etree.c:103323)
File "parser.pxi", line 683, in lxml.etree._handleParseResult (src\lxml\lxml.etree.c:104977)
File "parser.pxi", line 613, in lxml.etree._raiseParseError (src\lxml\lxml.etree.c:103886)
lxml.etree.XMLSyntaxError: Premature end of data in tag event line 784, line 786, column 7
tree = etree.parse('1.xml')
Answer the question
In order to leave comments, you need to log in
Try like this:
....
your_data = StringIO.StringIO()
your_data.write(xml)
your_data.seek(0)
tree = etree.parse(your_data)
tree = etree.parse(file_events)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question