MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 686

Developing coldfusion mx applications
Table of Contents

Advertisement

{
if (xmlElement.XmlChildren[i].XmlName IS nodeName)
nodesFound = nodesFound + 1;
}
return nodesFound;
}
</cfscript>
The following lines use this function to display the number of nodes named "name" in the
mydoc.employee element:
<cfoutput>
Nodes Found: #NodeCount(mydoc.employee, "name")#
</cfoutput>
Determining the position of a child element with a common name
The
XmlChildPos
element with a common name. You use this index when you need to tell ColdFusion where to
insert or delete child elements. For example, if there are several name elements in
mydoc.employee, use the following code to locate name[2] in the
<cfset nameIndex = XmlChildPos(mydoc.employee, "name", 2)>
Adding an element
You can add an element by creating a new element or by using an existing element.
Use the
XmlElemNew
form:
XmlElemNew(docObject, elementName)
where docObject is the name of the XML document object in which you are creating the element,
and elementName is the name you are giving the new element.
Use an assignment statement with an existing element on the right side to create a new element
using an existing element. See
on adding elements using existing elements.
Adding an element using a function
You can use the
document object. For example, the following line adds a phoneNumber element after the last
element for employee.name[2]:
<cfset ArrayAppend(mydoc.employee.name[2].XmlChildren, XmlElemNew(mydoc,
"phoneNumber"))>
The following line adds a new department element as the first element in employee. The name
elements become the second and third elements.
<cfset ArrayInsertAt(mydoc.employee.XmlChildren, 1, XmlElemNew(mydoc,
"department"))>
You must use the format
you are adding the new element. For example, the following line causes an error:
<cfset ArrayInsertAt(mydoc.employee.name, 2, XmlElemNew(mydoc, "PhoneNumber")>
686
Chapter 31: Using XML and WDDX
function determines the location in the
function to create a new, empty element. This function has the following
"Copying an existing element" on page 687
or
ArrayInsertAt
ArrayAppend
parentElement
XmlChildren
functions to add an element to an XML
.
to specify the array of elements to which
XmlChildren
array of a specific
array:
XmlChildren
for more information

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents