ElementTree and utf-16 encoding
Sébastien Boisgérault
Sebastien.Boisgerault at gmail.com
Tue Dec 19 04:36:10 EST 2006
Hi,
ET being ElementTree in the following code, could anyone explain
why it fails ?
>>> xml = ET.tostring(ET.Element("root"), "UTF-16")
>>> xml
"<?xml version='1.0' encoding='UTF-16'?>\n<\xff\xfer\x00o\x00o\x00t\x00
/>"
>>> ET.fromstring(xml)
Traceback (most recent call last):
...
xml.parsers.expat.ExpatError: encoding specified in XML declaration is
incorrect: line 1, column 30
I s it related to the lack of BOM in the xml string ?
I tried to add some "\xff\xfe" or "\xfe\xff" at the start of the xml
string without much sucess with fromstring so far ...
Cheers,
SB
More information about the Python-list
mailing list