Creating And Saving An Xml Document Object; Creating A New Xml Document Object Using The Cfxml Tag; Creating A New Xml Document Object Using The Xmlnew Function - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

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>

Creating and saving an XML document object

The following sections show the ways you can create and save an XML document object. The
specific technique you use will depend on the application and your coding style.

Creating a new XML document object using the cfxml tag

The
tag creates an XML document object that consists of the XML markup in the tag
cfxml
body. The tag body can include CFML code. ColdFusion processes the CFML code and includes
the resulting output in the XML. The following example shows a simple
<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
document object.
Note: When you use the
This directive is not required, and causes an error. To process XML text that includes the <?xml ?>
directive, use the

Creating a new XML document object using the XmlNew function

The
function creates a new XML document object, which you must then populate. The
XmlNew
following example creates and displays the same ColdFusion document object as in
new XML document object using the cfxml tag" on page
<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)
680
Chapter 31: Using XML and WDDX
cfloop
tag, do not include an <?xml ?> processing directive in the tag body.
cfxml
XmlParse
function.
tag. The
tag displays the resulting XML
cfdump
680:
tag:
cfxml
"Creating a

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents