Adobe COLDFUSION 9 Manual page 1087

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
The ColdFusion page
The ColdFusion page looks like the following:
<!--- Convert file to XML document object --->
<cffile action="read" file="C:\CFusion\wwwroot\examples\order.xml" variable="myxml">
<cfset mydoc = XmlParse(myxml)>
<!--- Extract account number --->
<cfset accountNum=#mydoc.order.customer.XmlAttributes.accountNum#>
<!--- Display Order Information --->
<cfoutput>
<b>Name=</b>#mydoc.order.customer.XmlAttributes.firstname#
#mydoc.order.customer.XmlAttributes.lastname#
<br>
<b>Account=</b>#accountNum#
<br>
<cfset numItems = ArrayLen(mydoc.order.items.XmlChildren)>
<b>Number of items ordered=</b> #numItems#
</cfoutput>
<br><br>
<!--- Process the order into a query object --->
<cfset orderquery = QueryNew("item_Id, name, qty, unitPrice") >
<cfset temp = QueryAddRow(orderquery, #numItems#)>
<cfloop index="i" from = "1" to = #numItems#>
<cfset temp = QuerySetCell(orderquery, "item_Id",
#mydoc.order.items.item[i].XmlAttributes.id#,#i#)>
<cfset temp = QuerySetCell(orderquery, "name",
#mydoc.order.items.item[i].name.XmlText#, #i#)>
<cfset temp = QuerySetCell(orderquery, "qty",
#mydoc.order.items.item[i].quantity.XmlText#, #i#)>
<cfset temp = QuerySetCell(orderquery, "unitPrice",
#mydoc.order.items.item[i].unitprice.XmlText#, #i#)>
</cfloop>
<!--- Display the order query --->
<cfdump var=#orderquery#>
<br><br>
<!--- Determine the discount --->
<cfquery name="discountQuery" datasource="cfdocexamples">
SELECT *
FROM employee
WHERE Emp_Id = #accountNum#
</cfquery>
<cfset drate = 0>
<cfif #discountQuery.RecordCount# is 1>
<cfset drate = 10>
</cfif>
<!--- Display the discount rate --->
<cfoutput>
<b>Discount Rate =</b> #drate#%
</cfoutput>
<br><br>
<!--- Compute the total cost and discount price--->
Last updated 8/5/2010
1082

Advertisement

Table of Contents
loading

Table of Contents