Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 1083

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
<!--- Read the file and convert it to an XML document object --->
<cffile action="read" file="C:\CFusion\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#>
Converting a query object to XML
The following example shows how to convert a query object to XML. It uses
the cfdocexamples database and saves the information as an XML document.
Last updated 1/20/2012
to get a list of employees from
cfquery
1078

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents