XML/XPath: Difference between revisions

Content added Content deleted
(Properly ordering the languages)
(Add ColdFusion)
Line 60: Line 60:
// Convert the generic list to an array and output the count of items.
// Convert the generic list to an array and output the count of items.
Console.WriteLine(NodesValues.ToArray().Length);
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]]==
==[[PHP]]==