How to create a CDATA XML node

Antun Karlovac antun at antunkarlovac.com
Thu Mar 20 13:34:21 EST 2003


How do I implement a CDATA node in Python? I'm using dom.minidom as
follows:-

        impl = xml.dom.minidom.getDOMImplementation()
        doc = impl.createDocument( None, "element", None )
        root = doc.documentElement

Then I want to create my CDATA node. The reason I want a CDATA node is
because I want to preserve all the HTML formatting tags (i.e. the
<p>'s here) in the text node:-

        longDescText = '<p>There will be more text here.</p>'
        longDescText = longDescText
        longDescNode = doc.createElement( 'longdescription' )
        longDescTextNode = doc.createTextNode( longDescText )
        longDescNode.appendChild( longDescTextNode )
        root.appendChild( longDescNode )

I can't anything in either the docs, or the Python & XML O'Reilly
book. Am I blind or summat?

-Antun




More information about the Python-list mailing list