Listing 1

<?xml version="1.0"?>
<BEANS>
<BEAN ID="1">
<BEAN_NAME>Cubita</BEAN_NAME>
<BEAN_DESCRIPTION>Cubita Coffee is sun dried and hand sorted. It originates from an elevation of over 2000 meters in the Andes Mountains of Ecuador, which is located closest to the sun on the Equator. Superb aroma and rich Flavor.</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>12.0000</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="2">
<BEAN_NAME>Colombian Supremo</BEAN_NAME>
<BEAN_DESCRIPTION>This smooth, full-flavored coffee from Colombia boasts a sweet delicate aroma and a rich, balanced flavor. A classic coffee appropriate for any occasion.</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>13.5000</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="3">
<BEAN_NAME>Pure Kona Fancy</BEAN_NAME>
<BEAN_DESCRIPTION>Grown on the Big Island of Hawaii, this coffee is known for its tantalizing aroma. This medium bodied brew offers a rich flavor with subtle winery tones.</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>15.9000</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="4">
<BEAN_NAME>Kenyan</BEAN_NAME>
<BEAN_DESCRIPTION>The complex coffee from the highlands of East Africa features a winey, full flavor coupled with an intriguing aroma. A delightfully delicate selection for coffee lovers.</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>24.0000</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="5">
<BEAN_NAME>Costa Rican</BEAN_NAME>
<BEAN_DESCRIPTION>Arabicas normally set aside for the demanding Northern European market produce this lively, well-balanced coffee distinguished by its snappy, clean taste. Try it!</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>12.3000</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="6">
<BEAN_NAME>Kona Peaberry</BEAN_NAME>
<BEAN_DESCRIPTION>Occasionally coffee fruit produces a single, rather than a double, bean. These "peaberries" provide all the flavor and aroma of their larger, regular cousins, but in a smaller package.</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>10.0000</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="7">
<BEAN_NAME>Sumatra</BEAN_NAME>
<BEAN_DESCRIPTION>The wonderful cocoa-like finish of this smooth, full-bodied coffee is reminiscent of rich, dark chocolate. Its unique characteristics can only be captured from the rich soils of this isle of Indonesia.</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>9.5000</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="8">
<BEAN_NAME>Kona Blend</BEAN_NAME>
<BEAN_DESCRIPTION>25% Kona, 25% Sumatra and 50% Colombian. This combination unites the fragrant aroma of Kona with the full body of Sumatra and the dry snap of Colombian.</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>12.1500</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="9">
<BEAN_NAME>Kona Espresso</BEAN_NAME>
<BEAN_DESCRIPTION>Some like it dark roasted to give it the smokey, bittersweet tan that espresso drinkers crave.</BEAN_DESCRIPTION>
<PRICE_PER_UNIT>13.0000</PRICE_PER_UNIT>
</BEAN>
<BEAN ID="10">
<BEAN_NAME>Italian Roast</BEAN_NAME>
<BEAN_DESCRIPTION>Roasted in the Southern Italian tradition, this boldly flavored dark roast is a perfect choice for either a hearty cup of drip coffee or a shot of espresso. </BEAN_DESCRIPTION>
<PRICE_PER_UNIT>11.9000</PRICE_PER_UNIT>
</BEAN>
</BEANS>

Listing 2

<!--- bean_list.cfm
Displays a list of coffee
beans from an XML file --->

<!--- Import the file from disk and parse into
an XML document object --->
<cffile action="READ" variable="xml"
file="#ExpandPath('.')#\beans.xml">
<cfset xmlBeans=xmlParse(xml)>

<h1>Bean List</h1>

<!--- Set an Array reference to
Elements named "Bean" --->
<cfset aBeans=xmlBeans.Beans.Bean>

<!--- Start the HTML table --->
<table border="1">

<!--- Header Row --->
<tr bgcolor="aqua" valign="top">
<th>Bean Name</th>
<th>Bean Description</th>
<th>Price</th>
</tr>

<!--- Loop through the list of Bean elements
and output each Bean's name, description
and price --->
<cfoutput>
<cfloop from="1" to="#ArrayLen(aBeans)#" index="i">
<cfif i mod 2>
<cfset bgcolor="white">
<cfelse>
<cfset bgcolor="silver">
</cfif>
<cfset id=aBeans[i].XmlAttributes.ID>
<cfset price=aBeans[i].Price_Per_Unit.XmlText>
<tr valign="top" bgcolor="#bgcolor#">
<td><a href="beans.cfm?id=#id#">
#aBeans[i].Bean_Name.XmlText#</a></td>
<td>#aBeans[i].Bean_Description.XmlText#</td>
<td align="right">#DollarFormat(price)#</td>
</tr>
</cfloop>
</cfoutput>

</table>

Listing 3

<!---
bean_detail.cfm
Displays detail information about a single coffee bean
from an XML file
--->

<!--- Import the file from disk and parse into XML doc object --->
<cffile action="READ" variable="xml"
file="#ExpandPath('.')#\beans.xml">
<cfset xmlBeans=xmlParse(xml)>

<!--- Search for the one bean in URL.ID --->
<cfset aBeans=XmlSearch(xmlBeans, "//BEAN[@ID=#URL.ID#]")>

<!--- If we didn't get back a single bean, return to list --->
<cfif arrayLen(aBeans) neq 1>
<cflocation url="beans.cfm">
</cfif>

<!--- Output bean detail --->
<cfset Bean=aBeans[1]>
<cfoutput>
<h1>#Bean.Bean_Name.XmlText#</h1>
<p>#Bean.Bean_Description.XmlText#</p>
<p>#DollarFormat(Bean.Price_Per_Unit.XmlText)#/lb.</p>
<hr>
<p><a href="#cgi.script_name#">Back to List</a></p>
</cfoutput>

Listing 4

<!---
beans.cfm
A file to call either the detail or list view,
depending on whether a Bean ID has been provided
--->

<!--- Begin HTML Output --->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Coffee Bean Information</title>
</head>

<body>

<cfif IsDefined("URL.ID")>
<!--- If the user clicked on a single bean,
display detail info --->
<cfinclude template="bean_detail.cfm">
<cfelse>
<!--- If the page was called without a click,
display a list of beans --->
<cfinclude template="bean_list.cfm">
</cfif>

</body>
</html>