| Contents > Developing ColdFusion MX Applications > Using XML and WDDX > Using an XML object > Assigning data to an XML object 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>
|
|
||
| Contents > Developing ColdFusion MX Applications > Using XML and WDDX > Using an XML object > Assigning data to an XML object Assigning and retrieving CDATA values |
|
|
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6.1
Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.