User Guide

Table Of Contents
Using an XML object 853
Caution: Because ColdFusion always treats variable names as case-insensitive, using dot
notation for element and attribute names in a case sensitive XML document can generate
unexpected results (such as all-uppercase variable names), exceptions, or both.
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.
Use an array index to specify one of multiple elements with the same name; for example,
#mydoc.employee.name[1] and #mydoc.employee.name[2].
If you omit the array index on the last component of an element identifier, ColdFusion treats
the reference as the array of all elements with the specified name. For example,
mydoc.employee.name refers to an array of two name elements.
Use an array index into the XmlChildren array to specify an element without using its name;
for example,
mydoc.XmlRoot.XmlChildren[1].
Use associative array (bracket) notation to specify an element name that contains a period or
colon; for example,
myotherdoc.XmlRoot["Type1.Case1"].
You can use DOM methods in place of structure entry names.
For example, the following variables all refer to the
XmlText value “Almanzo” in the XML
document created in A simple XML document” on page 845:
mydoc.XmlRoot.XmlChildren[1].XmlChildren[1].XmlText
mydoc.employee.name[1].first.XmlText
mydoc.employee.name[1]["first"].XmlText
mydoc["employee"].name[1]["first"].XmlText
mydoc.XmlRoot.name[1].XmlChildren[1]["XmlText"]
The following variables all refer to the EmpType attribute of the first name element in the XML
document created in A simple XML document” on page 845:
mydoc.employee.name[1].XmlAttributes.EmpType
mydoc.employee.name[1].XmlAttributes["EmpType"]
mydoc.employee.XmlChildren[1].XmlAttributes.EmpType
mydoc.XmlRoot.name[1].XmlAttributes["EmpType"]
mydoc.XmlRoot.XmlChildren[1].XmlAttributes.EmpType
Neither of these lists contains a complete set of the possible combinations that can make up a
reference to the value or attribute.
Assigning data to an XML object
When you use an XML object reference on the left side of an expression, most of the preceding
rules apply to the reference up to the last element in the reference string.
For example, the rules in “Referencing the contents of an XML object” on page 852 apply to
mydoc.employee.name[1].first in the following expression:
mydoc.employee.name[1].first.MyNewElement = XmlElemNew(mydoc, NewElement);