I came up with a little short cut earlier today when I was commenting on an article Ben Nadel wrote and he thought it was pretty clever, so I thought other people might find it useful as well.
Before ColdFusion 8, if I was reading an XML document, I would use XMLSearch to create an array, then use cfloop to process each node that matched my xmlSearch, like this:
<cfxml variable="MyXMLDoc">
<?xml version='1.0' encoding='utf-8' ?>
<books>
<book>
<isbn>0321330110</isbn>
<title>Macromedia ColdFusion MX 7 Certified Developer Study Guide</title>
<author>Ben Forta</author>
</book>
<book>
<isbn>0596004206</isbn>
<title>Learning XML, Second Edition</title>
<author>Erik Ray</author>
</book>
<book>
<isbn>0782140297</isbn>
<title>Coldfusion MX Developer's Handbook</title>
<author>Raymond Camden</author>
</book>
</books>
</cfxml>
<!--- get an array of book nodes using xmlSearch --->
<cfset BookNodes = xmlSearch(MyXMLDoc,'/books/book')>
<!--- loop through the array and output the data --->
<cfoutput>
<cfloop from="1" to="#arraylen(BookNodes)#" index="i">
<cfset BookXML = xmlparse(BookNodes[i])>
<b>ISBN:</b> #BookXML.book.isbn.xmltext#<br>
<b>Title:</b> #BookXML.book.title.xmlText#<br>
<b>Author:</b> #BookXML.book.author.xmlText#<br><br>
</cfloop>
</cfoutput>
With the new "Array" attribute in ColdFusion 8's CFLoop tag, you can combine that two step process in to one CFLoop tag by placing the xmlSearch() function within the array attribute like this:
<cfxml variable="MyXMLDoc">
<?xml version='1.0' encoding='utf-8' ?>
<books>
<book>
<isbn>0321330110</isbn>
<title>Macromedia ColdFusion MX 7 Certified Developer Study Guide</title>
<author>Ben Forta</author>
</book>
<book>
<isbn>0596004206</isbn>
<title>Learning XML, Second Edition</title>
<author>Erik Ray</author>
</book>
<book>
<isbn>0782140297</isbn>
<title>Coldfusion MX Developer's Handbook</title>
<author>Raymond Camden</author>
</book>
</books>
</cfxml>
<cfoutput>
<!---
Loop over the array using a ColdFusion's new Array
iteration loop, using XMLSearch to create the array on the fly.
--->
<cfloop
index="BookXML"
array="#xmlsearch(MyXMLDoc,'/books/book')#">
<cfset BookXML = xmlparse(BookXML)>
<!--- Output the data. --->
<b>ISBN:</b> #BookXML.book.isbn.xmltext#<br>
<b>Title:</b> #BookXML.book.title.xmlText#<br>
<b>Author:</b> #BookXML.book.author.xmlText#<br><br>
</cfloop>
</cfoutput>
http://www.bennadel.com/index.cfm?dax=blog:1104.vi...
Awesome tip Scott.
<cfset local.aBooks = xmlsearch(MyXMLDoc,'/books/book') />
<cfloop
index="BookXML"
array="#local.aBooks#">
[....]
</cfloop>