I am using python 2.6.2 xml.etree.cElementTree to create an XML document:
import xml.etree.cElementTree as etree elem = etree.Element('tag') elem.text = (u"Würth Elektronik Midcom").encode('utf-8') xml = etree.tostring(elem,encoding='UTF-8')
At the end of the day, the xml looks like this:
<?xml version='1.0' encoding='UTF-8'?> <tag>Würth Elektronik Midcom</tag>
It seems like tostring ignored the encoding parameter and encoded "ü" into some other character encoding ("ü" is the correct utf-8 encoding, I'm sure).
Any advice regarding what I am doing wrong will be greatly appreciated.
python tostring xml utf-8
smock
source share