saxutils.XMLGenerator and CDATA

chris chris.stromberger at gmail.com
Fri Jan 20 18:14:49 EST 2006


Confused somewhat xml newbie.  I'm trying to output xml with a CDATA
section, using saxutils.XMLGenerator, but the output contains escaped
'<' and '>'  and '&' from the CDATA element.  Shouldn't it be spit out
intact?

Here's code and output:

from xml.sax import saxutils
import sys
handler = saxutils.XMLGenerator(sys.stdout)
handler.startDocument()
handler.startElement('sometag', {})
handler.characters('<![CDATA[x&<>xxx]]>')
handler.endElement('sometag')
handler.endDocument()

Produces:
<?xml version="1.0" encoding="iso-8859-1"?>
<sometag><![CDATA[x&<>xxx]]></sometag>

I was expecting to see
<?xml version="1.0" encoding="iso-8859-1"?>
<sometag><![CDATA[x&<>xxx]]></sometag>

What am I doing wrong here?

Thanks,
Chris




More information about the Python-list mailing list