<cfset parent = XMLParse(parent)>
No no. This is even a performance penalty, because you are creating a new DOM this way.
You get an array of XML nodes from XmlSearch() (why else would you use a <cfloop array... ?). This means that they must be equivalent:
<cfloop array="#parents#" index="parent"> <cfdump var="#parent#"> </cfloop> <cfloop from="1" to="#ArrayLen(parents)#" index="i"> <cfdump var="#parents[i]#"> </cfloop>
To create a ColdFusion fame context when searching for a node, you need to do:
XMLSearch(parent, ".//child") -------------------^
If you start an XPath expression with "//" , ColdFusion obviously looks for the entire document to which the node belongs, not just the node descendants.
But if you are interested in outputting all <child> elements from a document, why not do this:
<cfset children = XMLSearch(xml, "//child")>
Tomalak
source share