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

Developing coldfusion mx applications
Table of Contents

Advertisement

When you copy an element, the new element must have the same name as the existing element. If
you specify the new element by name on the left side of an assignment, the element name must be
the same as the name on the right side. For example, the following expression causes an error:
<cfset mydoc.employee.name[2].telephne = mydoc.employee.name[1].phoneNumber>
Deleting elements
There are many ways to delete individual or multiple elements.
Deleting individual elements
Use the
function to delete a specific element from an XML document object. For
ArrayDeleteAt
example, the following line deletes the second child element in the mydoc.employee element:
<cfset ArrayDeleteAt(mydoc.employee.XmlChildren, 2)>
If an element has only one child element with a specific name, you can also use the
function to delete the child element. For example, the following line deletes the
StructDelete
phoneNumber element named in the second employee.name element:
<cfset StructDelete(mydoc.employee.name[2], "phoneNumber")>
When there are multiple child elements of the same name, you must specify the element position,
either among the elements of the same name, or among all child elements. Fore example, you can
use the following line to delete the second name element in mydoc.employee:
<cfset ArrayDeleteAt(mydoc.employee.name, 2)>
You can also determine the position in the
array of the element you want to delete
XmlChildren
and use that position. To do so, use the
function. For example, the following lines
XmlChildPos
determine the location of mydoc.employee.name[2] and delete the element:
<cfset idx = XmlChildPos(mydoc.employee, "name", 2)>
<cfset ArrayDeleteAt(mydoc.employee.XmlChildren, idx)>
Deleting multiple elements
If an element has multiple children with the same name, use the
function or
StructDelete
function with an element name to delete all of an element's child elements with that
ArrayClear
name. For example, both of the following lines delete all name elements from the employee
structure:
<cfset StructDelete(mydoc.employee, "name")>
<cfset ArrayClear(mydoc.employee.name)>
Use the
or
function with
to delete all of an element's
StructDelete
ArrayClear
XmlChildren
child elements. For example, each of the following lines deletes all child elements of the
mydoc.employee.name[2] element:
<cfset StructDelete(mydoc.employee.name[2], "XmlChildren")>
<cfset ArrayClear(mydoc.employee.name[2].XmlChildren)>
688
Chapter 31: Using XML and WDDX

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents