[XML-SIG] UnicodeError: ASCII encoding error: ordinal not in
range(128)
David Gaya
david.gaya at terra.es
Tue Nov 25 08:00:30 EST 2003
Hi,
I'm quite new in python but I see it has good support for XML. I'm trying to
modify an XML file using DOM. My script is the following:
from xml.dom import minidom
xmldoc = minidom.parse('slide.xml')
bitmaplist = xmldoc.getElementsByTagName('Bitmap')
for bitmap in bitmaplist:
cdata = bitmap.firstChild
bitmap.removeChild(cdata)
print xmldoc.toxml()
I got the following error:
UnicodeError: ASCII encoding error: ordinal not in range(128)
This is because xml file contains some strings like:
<StyleBox>
<String></String>
</StyleBox>
Instead of 'print xmldoc.toxml()' I've tryed
s = xmldoc.toxml()
print s.encode('UTF-8')
But then  is encoded in a single character.
Does anybody know how can I print (or save) back the modified document
keeping the  format ?
Thanks very much
David
More information about the XML-SIG
mailing list