error at converting xml-file into python object

I’m trying to parse an XML-file into a python object. Someone else had a similar question, and here’s the link to that:

Parse XML file into Python object

My code looks as follows:

from lxml import tree import xml.etree.cElementTree as ET  tree = etree.parse("part_000001.xml") #load file tree.xinclude()                                                  #recursively includes files string = etree.tostring(tree, pretty_print=True).decode("utf-8") #decode will convert bytes into string print(string)  new_tree=ET.fromstring(string) #THIS LINE DOESNT WORK 

adding the last line of code results into an error. The string I am using is not a multi-line string, but an ordinary string in the form " … ", could that be an issue?

Here’s what the error looks like:

Traceback (most recent call last):

File "<string>", line unknown ParseError: unbound prefix: line 12, column 17 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.