XMLNEW  
Description

Creates an XML document object.

 
Returns

An empty XML document object.

 
Category

XML functions

 
Function syntax
XmlNew([caseSensitive])
 
See also

cfxml, IsXmlDoc, ToString, XmlFormat, XmlParse, XmlValidate; Chapter 35, "Using XML and WDDX" in ColdFusion MX Developer's Guide

 
History

ColdFusion MX: Added this function.

 
Parameters

 
Usage

An XML document object is represented in ColdFusion as a structure.

The caseSensitive parameter value determines whether identifiers whose characters are of varying case, but are otherwise the same, refer to different components; for example:

  • If True, the element or attribute names "name" and "NAME" refer to different elements or attributes.
  • If False, these names refer to the same elements or attributes.

If your XML object is case sensitive, you cannot use dot notation to reference an element or attribute name. Use the name in associative array (bracket) notation, or a reference that does not use the case-sensitive name (such as xmlChildren[1]) instead. In the following code, the first line will work with a case-sensitive XML object. The second and third lines cause errors:

MyDoc.xmlRoot.XmlAttributes["Version"] = "12b";
MyDoc.xmlRoot.XmlAttributes.Version = "12b";
MyDoc.MyRoot.XmlAttributes["Version"] = "12b";

To convert an XML document object into a string, use the ToString function.

 
Example

The following example creates and displays a ColdFusion document object:

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

Determines how ColdFusion processes the case of XML document object component identifiers:

CASESENSITIVE