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

Developing coldfusion mx applications
Table of Contents

Advertisement

Adding, changing, and deleting element attributes
You modify an element's attributes the same way you change the contents of any structure. For
example, each of the following lines adds a Status attribute the second mydoc.employee.name
element:
<cfset mydoc.employee.name[2].XmlAttributes.Status="Inactive">
<cfset StructInsert(mydoc.employee.name[2].XmlAttributes, "Status",
"Inactive")>
To change an attribute, use a standard assignment statement; for example:
<cfset mydoc.employee.name[2].XmlAttributs.Status="Active">
To delete an attribute, use StructDelete; for example:
<cfset StructDelete(mydoc.employee.name[1].XmlAttributes, "Status")>
Changing element properties
To change an element's properties, including its text and comment, use a standard assignment
expression. For example, use the following line to add "in the MyCompany Documentation
Department" to the mydoc.employee XML comment:
<cfset mydoc.employee.XmlComment = mydoc.employee.XmlComment & "in the
MyCompany Documentation Department">
Changing an element name
The XML DOM does not support changing an element name directly. To change the name of an
element, you must create a new element with the new name, insert it into the XML document
object before or after the original element, copy all the original element's contents to the new
element, and then delete the original element.
Clearing an element property value
To clear an element property value, either assign the empty string to the property or use the
function. For example, each of the following lines clears the comment string from
StructDelete
mydoc.employee:
<cfset mydoc.employee.XmlComment = "">
<cfset StructDelete(mydoc.employee, "XmlComment")>
Replacing or moving an element
To replace an element with a new element, use a standard replacement expression. For example, to
replace the mydoc.employee.department element with a new element named organization, use
either of the following lines:
<cfset mydoc.employee.department = XmlElemNew(mydoc, "Organization")>
<cfset mydoc.employee.XmlChildren[1] = XmlElemNew(mydoc, "Organization")>
To replace an element with a copy of an existing element, use the existing element on the right
side of an expression. For example, the following line replaces the phoneNumber element for
mydoc.employee.name[2] with the phoneNumber element from mydoc.employee.name[1]:
<cfset mydoc.employee.name[2].phoneNumber=mydoc.employee.name[1].phoneNumber>
This creates a true copy of the name[1].phoneNumber element as name[2].phoneNumber.
Modifying a ColdFusion XML object
689

Advertisement

Table of Contents
loading
Need help?

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

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion mx

Table of Contents