Phix
include builtins\xml.e -- (needs 0.8.0+)
string xml_text = get_text("C:\\Users\\Pete\\sample.xml")
sequence xml = xml_parse(xml_text)
sequence foods = get_xml_nodes(xml[XML_CONTENTS],"food")
for i=1 to length(foods) do
string name = get_xml_nodes(foods[i],"name")[1][XML_CONTENTS],
sodium = get_xml_nodes(foods[i],"sodium")[1][XML_CONTENTS]
printf(1,"%s has a sodium level of %s\n",{name,sodium})
end for
Output
Avocado Dip has a sodium level of 210
Bagels, New York Style has a sodium level of 510
Beef Frankfurter, Quarter Pound has a sodium level of 1100
Chicken Pot Pie has a sodium level of 810
Cole Slaw has a sodium level of 15
Eggs has a sodium level of 65
Hazelnut Spread has a sodium level of 20
Potato Chips has a sodium level of 180
Soy Patties, Grilled has a sodium level of 420
Truffles, Dark Chocolate has a sodium level of 10
Pete