-module(xml_xpath). -include_lib("xmerl/include/xmerl.hrl"). -export([main/0]). main() -> XMLDocument = "
Invisibility Cream 14.50 Makes you invisible Levitation Salve 23.99 Levitate yourself for up to 3 hours per application
Blork and Freen Instameal 4.95 A tasty meal in a tablet; just add water Grob winglets 3.56 Tender winglets of Grob. Just add water
", {Document,_} = xmerl_scan:string(XMLDocument), io:format("First item:\n~s\n", [lists:flatten( xmerl:export_simple( [hd(xmerl_xpath:string("//item[1]", Document))], xmerl_xml, [{prolog, ""}]))]), io:format("Prices:\n"), [ io:format("~s\n",[Content#xmlText.value]) || #xmlElement{content = [Content|_]} <- xmerl_xpath:string("//price", Document)], io:format("Names:\n"), [ Content#xmlText.value || #xmlElement{content = [Content|_]} <- xmerl_xpath:string("//name", Document)].