Adobe COLDFUSION 9 Manual page 1073

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
<cfset testVar = True>
<cfxml variable="MyDoc">
<MyDoc>
<cfif testVar IS True>
<cfoutput>The value of testVar is True.</cfoutput>
<cfelse>
<cfoutput>The value of testVar is False.</cfoutput>
</cfif>
<cfloop index = "LoopCount" from = "1" to = "4">
<childNode>
This is Child node <cfoutput>#LoopCount#.</cfoutput>
</childNode>
</cfloop>
</MyDoc>
</cfxml>
<cfdump var=#MyDoc#>
This example creates a document object with a root element MyDoc, which includes text that displays the value of the
ColdFusion variable testVar. MyDoc has four nested child elements, which are generated by an indexed cfloop tag. The
tag displays the resulting XML document object.
cfdump
Note: When you use the
cfxml
required, and causes an error. To process XML text that includes the <?xml ?> directive, use the
Creating an XML document object using the XmlNew function
The
function creates an XML document object, which you must then populate. For information on how to
XmlNew
populate a new XML document, see
Note: You cannot set the
XmlDocType
The following example creates and displays the same ColdFusion document object as in
object using the cfxml
tag" on page 1067.
<cfset testVar = True>
<cfscript>
MyDoc = XmlNew();
MyDoc.xmlRoot = XmlElemNew(MyDoc,"MyRoot");
if (testVar IS TRUE)
MyDoc.MyRoot.XmlText = "The value of testVar is True.";
else
MyDoc.MyRoot.XmlText = "The value of testVar is False.";
for (i = 1; i LTE 4; i = i + 1)
{
MyDoc.MyRoot.XmlChildren[i] = XmlElemNew(MyDoc,"childNode");
MyDoc.MyRoot.XmlChildren[i].XmlText = "This is Child node " & i &".";
}
</cfscript>
<cfdump var=#MyDoc#>
Creating an XML document object from existing XML
The
function converts an XML document or document fragment represented as text into a ColdFusion
XmlParse
document object. You can use a string variable containing the XML or the name or URL of a file that contains the text.
For example, if your application uses
the XML document object:
<cfset myXMLDocument = XmlParse(cfhttp.fileContent)>
tag, do not include an <?xml ?> processing directive in the tag body. This directive is not
"Adding, deleting, and modifying XML
property for an XML document object that you create with the
cfhttp action="get"
Last updated 8/5/2010
elements" on page 1073.
"Creating an XML document
to get the XML document, use the following line to create
1068
function.
XmlParse
function.
XmlNew

Advertisement

Table of Contents
loading

Table of Contents