0

I follow the help of this thread. How do I get Python's ElementTree to pretty print to an XML file?

But i have an error that i didn't understand.

Error

File "myprogram.py", line 505, in get_phyloxml_extended
xmlstr = minidom.parseString(ET.tostring(root).decode("utf-8")).toprettyxml(indent="   ")
File "/usr/lib/python3.6/xml/dom/minidom.py", line 1968, in parseString
return expatbuilder.parseString(string)
File "/usr/lib/python3.6/xml/dom/expatbuilder.py", line 925, in parseString
return builder.parseString(string)
File "/usr/lib/python3.6/xml/dom/expatbuilder.py", line 223, in parseString
parser.Parse(string, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 425

Code

tree = ET.ElementTree(ET.fromstring(xml_string))
root = tree.getroot()
xmlstr = minidom.parseString(ET.tostring(root).decode("utf-8")).toprettyxml(indent="   ")
with open(file_ext_phyloxml_path, "w") as f:
    f.write(xmlstr.encode('utf-8'))
DalinDad
  • 103
  • 1
  • 14

1 Answers1

0

One of the label is a number so it doesnt work.....

like <phy:00000001>2.0<phy:00000001> not work

but...

BUT...

<phy:a00000001>2.0<phy:a00000001> work --'

DalinDad
  • 103
  • 1
  • 14