[Chicago] unicode -> xml

Massimo Di Pierro mdipierro at cs.depaul.edu
Thu Feb 19 19:13:43 CET 2009


Thank you this is exactly what I was looking for:

 >>> import codecs
 >>> enc = codecs.getencoder('us-ascii')
 >>> text=chr(245)
 >>> enc(text.decode('latin-1'),'xmlcharrefreplace')[0]
'õ'

Massimo

On Feb 19, 2009, at 10:40 AM, Brian Ray wrote:

>
> On Feb 19, 2009, at 10:23 AM, Massimo Di Pierro wrote:
>
>> problem. Given
>>
>>>>> a=chr(245).decode('latin-1').encode('utf8','xmlcharref')
>>>>> print a
>> õ
>>
>> how do I translate this into valid escaped XML "&U+xxxx;" in the
>> general case?
>>
>
> This reference mentions something along those lines:
>
>   <http://www.xml.com/pub/a/2005/06/15/py-xml.html>
>
> Does this help?
>
> Brian Ray
>
>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago



More information about the Chicago mailing list