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

Developing coldfusion mx applications
Table of Contents

Advertisement

Reviewing the code
The following table describes the CFML code and its function. For the sake of brevity, it does not
include code that displays the processing results.
Code
<cffile action="read"
file="C:\Neo\wwwroot\examples\order.xml"
variable="myxml">
<cfset mydoc = XmlParse(myxml)>
<cfset accountNum=#mydoc.order.
customer.XmlAttributes.accountNum#>
<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>
<cfquery name="discountQuery"
datasource="CompanyInfo">
SELECT *
FROM employee
WHERE Emp_Id = #accountNum#
</cfquery>
<cfset drate = 0>
<cfif #discountQuery.RecordCount# is 1>
<cfset drate = 10>
</cfif>
696
Chapter 31: Using XML and WDDX
Description
Reads the XML from a file and convert it to an
XML document object.
Sets the accountNum variable from the
customer entry's accountnum attribute.
Converts the XML document object into a
query object.
Creates a query with columns for the item_id,
name, qty, and unitPrice values for each item.
For each XML item entry in the
mydoc.order.items entry, fills one row of the
query with the item's id attribute and the text in
the name, quantity, and unitprice entries that
the it contains.
If the account number is the same as an
employee ID in the CompanyInfo database
Employee table, the query returns one record.
and RecordCount equals 1. In this case, sets a
discount rate of 10%. Otherwise, sets a
discount rate of 0%.

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

This manual is also suitable for:

Coldfusion mx

Table of Contents