minidom and åäö once again :-P
Magnus Heino
magnus.heino at sigma.pleon.se
Wed Apr 17 14:48:28 EDT 2002
Martin v. Löwis wrote:
> Magnus Heino <magnus.heino at pleon.sigma.se> writes:
>
>> >>> d.toxml()
>> '<?xml version="1.0" ?>\n<test>\xe5\xe4\xf6</test>'
>
> This is not what I'm getting. I get
>
> ...
> writer.write(data)
> File "/usr/local/lib/python2.2/StringIO.py", line 139, in write
> s = str(s)
> UnicodeError: ASCII encoding error: ordinal not in range(128)
>
> Apparently, you've changed the system default encoding, so that the
> conversion from Unicode strings to byte strings silently converted the
> Unicode string.
Well, I got confused by this;
http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.102.htp
But I have removed that now.
> In any case, your best bet is to use an explicitly-encoding stream:
>
>>>> s=StringIO.StringIO()
>>>> d.writexml(codecs.getwriter('utf-8')(s))
>>>> s.getvalue()
> '<?xml version="1.0" ?>\n<test>e\xc3\xa4\xc3\xb6</test>'
Ah.... there we go! Thank you for fast and accurate answers!
Now I finally understand whats going on, and why :-)
Maybe someone with commit access could add some short example like this one
to the python documentation for minidom?
--
/Magnus
More information about the Python-list
mailing list