elementtree XML() unicode

Kee Nethery kee at kagi.com
Wed Nov 4 01:01:46 CET 2009


Having an issue with elementtree XML() in python 2.6.4.

This code works fine:

      from xml.etree import ElementTree as et
      getResponse = u'''<?xml version="1.0" encoding="UTF-8"?>  
<customer><shipping><state>bobble</state><city>head</ 
city><street>city</street></shipping></customer>'''
      theResponseXml = et.XML(getResponse)

This code errors out when it tries to do the et.XML()

      from xml.etree import ElementTree as et
      getResponse = u'''<?xml version="1.0" encoding="UTF-8"?>  
<customer><shipping><state>\ue58d83\ue89189\ue79c8C</state><city> 
\ue69f8f\ue5b882</city><street>\ue9ab98\ue58d97\ue58fb03</street></ 
shipping></customer>'''
      theResponseXml = et.XML(getResponse)

In my real code, I'm pulling the getResponse data from a web page that  
returns as XML and when I display it in the browser you can see the  
Japanese characters in the data. I've removed all the stuff in my code  
and tried to distill it down to just what is failing. Hopefully I have  
not removed something essential.

Why is this not working and what do I need to do to use Elementtree  
with unicode?

Thanks, Kee Nethery



More information about the Python-list mailing list