MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 679

Developing coldfusion mx applications
Table of Contents

Advertisement

If the component name does not match an existing element, the element names on the left and
right sides of the expression must match. ColdFusion creates a new element with the name of
the element on the left of the expression. If the element names do not match, it generates an
error.
For example if there is no
expression creates a new
mydoc.employee.name.phoneNumber = XmlElemNew(mydoc, "phoneNumber");
The following expression causes an error:
mydoc.employee.name.phoneNumber = XmlElemNew(mydoc, "address");
If the component name does not match an existing element and the component's parent or
parents also do not exist, ColdFusion creates any parent nodes as specified on the left side and
use the previous rule for the last element. For example, if there is no
mydoc.employee.phoneNumber
element containing an AreaCode element:
mydoc.employee.name.phoneNumber.AreaCode = XmlElemNew(mydoc, "AreaCode");
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>
mydoc.employee.name.phoneNumber
mydoc.employee.name.phoneNumber
element, the following expression creates a phoneNumber
element, the following
element:
Using an XML object
679

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents