User Guide

Table Of Contents
Using an XML object 855
Assigning and retrieving CDATA values
To identify that element text is CDATA by putting it inside CDATA start and end marker
information items, assign the text to the XmlCdata element, not the XmlText element. You must
do this because ColdFusion escapes the < and > symbols in the element text when you assign it to
an XmlText entry. You can assign a value to an element’s XmlText entry or its XmlCdata entry,
but not to both, as each assignment overwrites the other.
When you retrieve data from the document object, references to XmlCdata and XmlText return
the same string.
The following example shows how ColdFusion handles CDATA text:
<cfscript>
myCDATA = "This is CDATA text";
MyDoc = XmlNew();
MyDoc.xmlRoot = XmlElemNew(MyDoc,"myRoot");
MyDoc.myRoot.XmlChildren[1] = XmlElemNew(MyDoc,"myChildNodeCDATA");
MyDoc.myRoot.XmlChildren[1].XmlCData = "#myCDATA#";
</cfscript>
<h3>Assigning a value to MyDoc.myRoot.XmlChildren[1].XmlCdata.</h3>
<cfoutput>
The type of element MyDoc.myRoot.XmlChildren[1] is:
#MyDoc.myRoot.XmlChildren[1].XmlType#<br>
The value when output using XmlCdata is:
#MyDoc.myRoot.XmlChildren[1].XmlCData#<br>
The value when output using XmlText is:
#MyDoc.myRoot.XmlChildren[1].XmlText#<br>
</cfoutput>
<br>
The XML text representation of Mydoc is:
<cfoutput><XMP>#tostring(MyDoc)#</XMP></cfoutput>
<h3>Assigning a value to MyDoc.myRoot.XmlChildren[1].XmlText.</h3>
<cfset MyDoc.myRoot.XmlChildren[1].XmlText = "This is XML plain text">
<cfoutput>
The value when output using XmlCdata is:
#MyDoc.myRoot.XmlChildren[1].XmlCData#<br>
The value when output using XmlText is:
#MyDoc.myRoot.XmlChildren[1].XmlText#<br>
</cfoutput>
<br>
The XML text representation of Mydoc is:
<cfoutput><XMP>#tostring(MyDoc)#</XMP></cfoutput>