Listing 1

<?xml version="1.0" encoding="UTF-8"?>
<directory>
   <employee>
       <name last="Smith" first="John" />
       <address>
           <street1>512 Goshen Road</street1>
           <street2/>
           <city>Bordell</city>
           <state>OH</state>
           <zip>35426</zip>
       </address>
   </employee>
</directory>


Listing 2:  "custorder.xml"

<?xml version="1.0" encoding="UTF-8"?>
<order id="E10645">
   <customer fname="Robert" lname="Finn" memberid="238"/>
   <items>
      <item id="544">
         <name>Headphones</name>
         <quantity>1</quantity>
         <unitprice>14.95</unitprice>
      </item>
      <item id="871">
         <name>CD Cleaner</name>
         <quantity>1</quantity>
         <unitprice>3.95</unitprice>
      </item>
      <item id="77">
         <name>Greatest Hits Album</name>
         <quantity>1</quantity>
         <unitprice>11.95</unitprice>
      </item>
   </items>
</order>

Listing 3:  "order.cfm"

<cffile action="read" file="#ExpandPath(".")#/custorder.xml" variable="strXmlOrder">

<cfset XmlOrder = XmlParse(strXmlOrder)>

<cfoutput>
<table>
<tr>
	<td>Order ID:</td>
	<td>#XmlOrder.xmlroot.XmlAttributes["id"]#</td>
</tr>
<tr>
	<td>Member Name:</td>
	<td>#XmlOrder.xmlroot.customer.XmlAttributes["lname"]#,
	 #XmlOrder.xmlroot.customer.XmlAttributes["fname"]#</td>
</tr>
<tr>
	<td>Member ID:</td>
	<td>#XmlOrder.xmlroot.customer.XmlAttributes["memberid"]#</td>
</tr>
<tr valign="top">
	<td>Items ordered</td>
	<td><table>
	<tr>
		<td>ID</td>
		<td>Item</td>
		<td>Qty</td>
		<td>Price</td>
	</tr>
      <cfloop from="1"
	      to="#ArrayLen(XmlOrder.xmlroot.items.XmlChildren)#"
		  index="i">
		<cfset xnItem = XmlOrder.xmlroot.items.XmlChildren[i]>
		<tr>
			<td>#xnItem.XmlAttributes["id"]#</td>
			<td>#xnItem.name.XmlText#</td>
			<td>#xnItem.quantity.XmlText#</td>
			<td>#xnItem.unitprice.XmlText#</td>
		</tr>
	</cfloop>
	</table></td>
</tr>
</table>
</cfoutput>

Listing 4: create XML using cfsavecontent

<cfsavecontent variable="cfsavecontent_example">
<report_using_cfsavecontent>
	<date>
<cfoutput>#DateFormat(now(),"mm/dd/yyyy")#</cfoutput>
</date>
	<topics>
		<topic name="Schedule">
We need to plan the new schedule
</topic>
		<topic name="Budget">
New budgets are available for review
</topic>
		<topic name="Supplies"/>
	</topics>
</report_using_cfsavecontent>
</cfsavecontent>
<cfset testXml = XmlParse(cfsavecontent_example)>
<cfdump var="#testXml#">

Listing 5: create XML using cfxml

<cfxml variable="cfxml_example">
<report_using_cfxml>
	<date>
<cfoutput>#DateFormat(now(),"mm/dd/yyyy")#</cfoutput>
</date>
	<topics>
		<topic name="Schedule">
We need to plan the new schedule
</topic>
		<topic name="Budget">
New budgets are available for review
</topic>
		<topic name="Supplies"/>
	</topics>
</report_using_cfxml>
</cfxml>
<cfdump var="#cfxml_example#">

Listing 6: XML Search

<!--- read my XML from a file --->
<cffile action="read" file="#ExpandPath(".")#/custorder.xml" variable="strXml">

<!--- parse into a CF XML Object --->
<cfset myXml = XmlParse(strXml)>

<!--- search for all "item" elements --->
<cfset myResultsArray = XMLSearch(myXml, "//item")>

<!--- just dump the results so we can see --->
<cfdump var="#myResultsArray#">