Using Xml And Coldfusion Queries - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

To move an element, you must assign it to its new location, then delete it from its old location.
For example, the following lines move the phoneNumber element from
mydoc.employee.name[1] to mydoc.employee.name[2]:
<cfset mydoc.employee.name[2].phoneNumber=mydoc.employee.name[1].phoneNumber>
<cfset StructDelete(mydoc.employee.name[1], "phoneNumber")>

Using XML and ColdFusion queries

You can convert XML documents into ColdFusion query objects and manipulate them using
queries of queries. This technique does not require the use of XPath and provides a method of
searching XML documents and extracting data that is natural to ColdFusion programmers.
Converting XML to a ColdFusion query
The following example reads an XML document, converts it to a query object, and then performs
a query of queries on the object to extract selected data:
<!--- Read the file and convert it to an XML document object --->
<cffile action="read" file="C:\Neo\wwwroot\myexamples\employees.xml"
variable="myxml">
<cfset mydoc = XmlParse(myxml)>
<!--- get an array of employees --->
<cfset emp = mydoc.employee.XmlChildren>
<cfset size = ArrayLen(emp)>
<cfoutput>
Number of employees = #size#
<br>
</cfoutput>
<br>
<!--- create a query object with the employee data --->
<cfset myquery = QueryNew("fname, lname") >
<cfset temp = QueryAddRow(myquery, #size#)>
<cfloop index="i" from = "1" to = #size#>
<cfset temp = QuerySetCell(myquery, "fname",
#mydoc.employee.name[i].first.XmlText#, #i#)>
<cfset temp = QuerySetCell(myquery, "lname",
#mydoc.employee.name[i].last.XmlText#, #i#)>
</cfloop>
<!--- Dump the query object --->
Contents of the myquery Query object: <br>
<cfdump var=#myquery#>
<br><br>
<!--- Select entries with the last name starting with A and dump the result --
->
<cfquery name="ImqTest" dbType="query">
SELECT lname, fname
FROM myquery
WHERE lname LIKE 'A%'
</cfquery>
<cfdump var=#imqtest#>
690
Chapter 31: Using XML and WDDX

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents