Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 1079

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Adding an element using a function
You can use the
ArrayInsertAt
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"))>
Use the format
parentElement
element. For example, the following line causes an error:
<cfset ArrayInsertAt(mydoc.employee.name, 2, XmlElemNew(mydoc, "PhoneNumber")>
If you have multiple child elements with the same name, and you want to insert a new element in a specific position,
use the function
XmlChildPos
element. For example, the following code determines the location of mydoc.employee.name[1] and inserts a new name
element as the second name element:
<cfscript>
nameIndex = XmlChildPos(mydoc.employee, "name", 1);
ArrayInsertAt(mydoc.employee.XmlChildren, nameIndex + 1, XmlElemNew(mydoc,
"name"));
</cfscript>
Using a namespace: When you use a function to add an element, you can assign the element to a namespace by
including the namespace prefix in the element name. If you have not yet associated the prefix with a namespace URI,
also include a parameter with the namespace URI in the
parameter in the method, and the element name must be the third parameter. ColdFusion then associates the
namespace prefix with the URI, and you can omit the URI parameter in further
The following example adds two to the supplies document root two elements in the Prod namespace. The first
function use sets the association between the Prod namespace prefix and the URI; the second use only
XmlElemNew
requires the prefix on the element name.
<cfscript>
mydoc.supplies.XmlChildren[1] = XmlElemNew(mydoc,
"http://www.foo.com/Products", "Prod:soap");
mydoc.supplies.XmlChildren[2] = XmlElemNew(mydoc, "Prod:shampoo");
</cfscript>
Adding an element using direct assignment
You can use direct assignment to append a new element to an array of elements. You cannot use direct assignment to
insert an element into an array of elements.
When you use direct assignment, you can specify on the left side an index into the
last child in the array. For example, if two elements exist in mydoc.employee, you can specify any number greater than
two, such as mydoc.employee.XmlChildren[6]. The element is always added as the last (in this case, third) child.
For example, the following line appends a name element to the end of the child elements of mydoc.employee:
<cfset mydoc.employee.XmlChildren[9] = XmlElemNew(mydoc, "name")>
or the
function to add an element to an XML document object. For
ArrayAppend
.
to specify the array of elements to which you are adding the new
XmlChildren
to determine the location in the
XmlElemNew
Last updated 1/20/2012
array where you want to insert the new
XmlChildren
function. This parameter must be the second
xmlElemNew
XmlChildren
1074
functions.
array greater than the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents