Jump to content

XML/XPath: Difference between revisions

Add ColdFusion
(Properly ordering the languages)
(Add ColdFusion)
Line 60:
// Convert the generic list to an array and output the count of items.
Console.WriteLine(NodesValues.ToArray().Length);
 
==[[ColdFusion]]==
<cfsavecontent variable="xmlString">
<inventory
...
</inventory>
</cfsavecontent>
<cfset xml = xmlParse(xmlString)>
&lt;!--- First Task --->
<cfset itemSearch = xmlSearch(xml, "//item")>
&lt;!--- item = the first Item (xml element object) --->
<cfset item = itemSearch[1]>
&lt;!--- Second Task --->
<cfset priceSearch = xmlSearch(xml, "//price")>
&lt;!--- loop and print each price --->
<cfloop from="1" to="#arrayLen(priceSearch)#" index="i">
#priceSearch[i].xmlText#&lt;br/>
</cfloop>
&lt;!--- Third Task --->
&lt;!--- array of all the name elements --->
<cfset names = xmlSearch(xml, "//name")>
&lt;!--- visualize the results --->
<cfdump var="#variables#">
 
==[[PHP]]==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.