Changing
Use the following techniques to change the contents of an element:
Type
Using a function
StructUpdate
Property
"propertyName", "value")
Attribute
StructUpdate(xmlElemPath.XmlAttributes,
"attributeName", "value")
Child
ArraySet
index,
element
index, newElement)
(replace)
(use the same value for both index entries to
change one element)
Adding, deleting, and modifying XML elements
The following sections describe the basic techniques for adding, deleting, and modifying XML
elements. The example code uses the XML document described in
on page
671.
Counting and finding the position of child elements
Often, an XML element has several children with the same name. For example, in the XML
document defined in the simple XML document, the employee root element has multiple name
elements.
To manipulate such an object, you often need to know the number of children of the same name,
and you might need to know the position in the
is used for multiple children. The following sections describe how to get this information.
Counting child elements
The following user-defined function determines the number of child elements with a specific
name in an element:
<cfscript>
function NodeCount (xmlElement, nodeName)
{
nodesFound = 0;
for ( i = 1; i LTE ArrayLen(xmlElement.XmlChildren); i = i+1)
(xmlElemPath,
(xmlElemPath.XmlChildren,
Using an assignment statement
xmlElemPath.propertyName =
"value"
xmlElemPath["propertyName"] =
"value"
xmlElemPath.XmlAttributes.
attributeName="value"
xmlElemPath.XmlAttributes
["attributeName"] = "value"
Replace first or only child named
elementName:
parentElemPath.elementName =
newElement
parentElemPath["elementName"]
= newElement
Replace a specific child named
elementName:
parentElemPath.elementName
[index] = newElement
or
parentElemPath["elementName"]
[index] = newElement
"A simple XML document"
array of a specific child name that
XmlChildren
Modifying a ColdFusion XML object
685
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