xml.dom.minidom character encoding

C. Benson Manica cbmanica at gmail.com
Wed Apr 21 13:19:57 EDT 2010

I have the following simple script running on 2.5.2 on a machine where
the default character encoding is "ascii":

#!/usr/bin/env python
#coding: utf-8

import xml.dom.minidom
import codecs

str=u"<?xml version=\"1.0\" encoding=\"utf-8\"?><elements><elem attrib=
doc=xml.dom.minidom.parseString( str )
xml=doc.toxml( encoding="utf-8" )
file=codecs.open( "foo.xml", "w", "utf-8" )
file.write( xml )

I've specified utf-8 every place I can find that the documentation
allows me to, and yet this doesn't even come close to working without
UnicodeEncodeErrors.  What on Earth do I have to do to please the
character encoding gods?

More information about the Python-list mailing list