Contents > Developing ColdFusion MX Applications > Using XML and WDDX > Creating and saving an XML document object > Creating a new XML document object using the XmlNew function PreviousNext

Creating a new XML document object using the XmlNew function

The XmlNew function creates a new XML document object, which you must then populate. The following example creates and displays the same ColdFusion document object as in Creating a new XML document object using the cfxml tag:

<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#>

Contents > Developing ColdFusion MX Applications > Using XML and WDDX > Creating and saving an XML document object > Creating a new XML document object using the XmlNew function PreviousNext

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.