elementtree.SimpleXMLWriter and xmlcharrefreplace

peterbe at gmail.com peterbe at gmail.com
Fri Jan 5 10:59:57 EST 2007


I'll try to explain my problem with code.
The problem is the output

msg = u"Södertälje & Borås" # latin1 unicode string with a &

from elementtree.SimpleXMLWriter import XMLWriter
from cStringIO import StringIO
out = StringIO()
w = XMLWriter(out)
body = w.start("body")
w.element("text", msg)
w.close(body)
return out.getvalue()

Here's the output I get:
<body><text>Södertälje &amp; Borås</text></body>
Here's what I would want and expect:
<body><text>Södertälje & Borås</text></body>

Notice that & is converted to &amp; when it should be & or &38;
only.




More information about the Python-list mailing list