Given the following XML:
<cfsavecontent variable="xml">
<root>
<parent>
<child>I'm the first</child>
<child>Second</child>
<child>3rd</child>
</parent>
<parent>
<child>Only child</child>
</parent>
<parent>
<child>I'm 10</child>
<child>I'm 11!</child>
</parent>
</root>
</cfsavecontent>
Is this the best way to loop over each parent and then extract all children from that parent?
<cfset xml = XMLParse(Trim(xml))>
<cfset parents = XMLSearch(xml, "//parent")>
<cfloop array="#parents#" index="parent">
<cfset parent = XMLParse(parent)><!--- Is this needed? --->
<cfset children = XMLSearch(parent, "//child")>
<cfloop array="#children#" index="child">
<cfoutput>#child.XmlText#</cfoutput>
</cfloop>
</cfloop>
The reason I ask is because I've never been able to extract all child elements from the current XML element.
The 'Is this needed?' comment highlights the line I added to make the proceeding line work. But is it possible to to remove this line and somehow change 'XMLSearch(parent, "//child")' to only get child elements from the current 'parent'?
Thanks.