How to create a CDATA XML node

Steven Taschuk staschuk at telusplanet.net
Thu Mar 20 21:55:54 EST 2003


Quoth Antun Karlovac:
> 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

As far as I know, DOM has no notion of CDATA nodes; they are
considered a low-level detail which does not properly belong in
the model.  (Similarly, you can't tell in DOM whether an attribute
value was delimited with ' or ".)  It's up to the DOM -> XML code
to escape markup characters in text, and it's up to the XML -> DOM
code to unescape them.  The DOM user just sees text.

-- 
Steven Taschuk                             staschuk at telusplanet.net
"I may be wrong but I'm positive."  -- _Friday_, Robert A. Heinlein





More information about the Python-list mailing list