"XML Or Text Declaration Not At Start Of Entity: Line 2, Column 0" When Calling ElementTree.parse
ElementTree.parse() fails in the simple example below with the error xml.etree.ElementTree.ParseError: XML or text declaration not at start of entity: line 2, column 0 The XML lo
Solution 1:
You have a newline at the beginning of the XML string, remove it:
xmlExample = """<?xml version="1.0"?>
...
Or, you may just strip()
the XML string:
source = io.StringIO(xmlExample.strip())
As a side note, you don't have to create a file-like buffer, and use .fromstring()
instead:
root = ET.fromstring(xmlExample)
Solution 2:
Found it... whitespace in front of 1st element...
Post a Comment for ""XML Or Text Declaration Not At Start Of Entity: Line 2, Column 0" When Calling ElementTree.parse"