[ACCEPTED]-Encoding issues with python's etree.tostring-tostring
Accepted answer
You're encoding the text twice. Try this:
import xml.etree.cElementTree as etree
elem = etree.Element('tag')
elem.text = u"Würth Elektronik Midcom"
xml = etree.tostring(elem, encoding='UTF-8')
0
etree.tostring(elem, encoding=str)
will return str
but not binary
in Python 3
You can 6 also serialise to a Unicode string without 5 declaration by passing the
unicode
function 4 as encoding (orstr
in Py3), or the 3 name 'unicode'. This changes the return 2 value from a byte string to an 1 unencoded unicode string.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.