encoding ascii data for xml

Dillon Collins dillonco at comcast.net
Sat Oct 4 02:25:43 CEST 2008


On Friday 03 October 2008, harrelson wrote:
> import xml.dom.minidom
> print chr(3).encode('utf-8')
> dom = xml.dom.minidom.parseString( "<test>%s</test>" %
> chr(3).encode('utf-8') )
>
> chr(3) is the ascii character for "end of line".  [...] My
> question is why doesn't encode() blow up?

You just answered your question.  0x03 may not be a printing character, but it 
is a valid character in the ascii character set and therefore is not a 
problem.  For xml, however, it is an illegal character so that's why the 
parser is throwing an error.



More information about the Python-list mailing list