[XML-SIG] XML Unicode and UTF-8

n.youngman at ntlworld.com n.youngman at ntlworld.com
Thu Aug 5 13:14:57 CEST 2004


> 
> From: "Martin v. Löwis" <martin at v.loewis.de>
> Date: 2004/08/05 Thu AM 10:41:59 GMT
> To: n.youngman at ntlworld.com
> CC: xml-sig at python.org
> Subject: Re: [XML-SIG] XML Unicode and UTF-8

<SNIP>

> State all the information that you have, preferably in the form:
> 1. this is what I did
> 2. this is what happened
> 3. this is what I expected to happen instead.
> 
> Regards,
> Martin

I missed out pass 4:

Create the node with

   unicode_tag.appendChild( doc.createTextNode( segment[0].encode( "utf-8") ) )

and print with 

    XMLFILE = open( filename, "w" )
    xml.documentElement.writexml( XMLFILE, indent="", addindent="", newl="")
    XMLFILE.close()

Produces the error
Traceback (most recent call last):
  File "./storemail.py", line 347, in ?
    save_message( message, raw_message, savedir + "/" + filename + ".xml" )
  File "./storemail.py", line 130, in save_message
    xml = message_to_xml( message, raw_message )
  File "./storemail.py", line 179, in message_to_xml
    entity_tag = entity_to_xml( entity, doc )
  File "./storemail.py", line 215, in entity_to_xml
    unicode_tag.appendChild( doc.createTextNode( segment[0].encode( "utf-8") ) )
UnicodeDecodeError: 'ascii' codec can't decode byte 0xee in position 0: ordinal not in range(128)


-----------------------------------------
Email provided by http://www.ntlhome.com/




More information about the XML-SIG mailing list