Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
63 lines (58 sloc) 1.89 KB
#~
# compile: obc -src xml_2.obs -lib xml.obl,gen_collect.obl -dest xml_2.obe
# run: obr xml_2.obe
~#
use System.IO;
use Data.XML;
class Test {
function : Main(args : String[]) ~ Nil {
in := "";
in += "<inventory title=\"OmniCorp Store #45x10^3\">";
in += "<section name=\"health\">";
in += "<item upc=\"123456789\" stock=\"12\">";
in += "<name>Invisibility Cream</name>";
in += "<price>14.50</price>";
in += "<description>Makes you invisible</description>";
in += "</item>";
in += "<item upc=\"445322344\" stock=\"18\">";
in += "<name>Levitation Salve</name>";
in += "<price>23.99</price>";
in += "<description>Levitate yourself for up to 3 hours per application</description>";
in += "</item>";
in += "</section>";
in += "<section name=\"food\">";
in += "<item upc=\"485672034\" stock=\"653\">";
in += "<name>Blork and Freen Instameal</name>";
in += "<price>4.95</price>";
in += "<description>A tasty meal in a tablet; just add water</description>";
in += "</item>";
in += "<item upc=\"132957764\" stock=\"44\">";
in += "<name>Grob winglets</name>";
in += "<price>3.56</price>";
in += "<description>Tender winglets of Grob. Just add water</description>";
in += "</item>";
in += "</section>";
in += "</inventory>";
parser := XmlParser->New(in);
if(parser->Parse()) {
# get first item
results := parser->FindElements("/inventory/section[1]/item[1]");
if(results <> Nil) {
Console->Print("items: ")->PrintLine(results->Size());
};
# get all prices
results := parser->FindElements("/inventory/section/item/price");
if(results <> Nil) {
each(i : results) {
element := results->Get(i)->As(XmlElement);
element->GetContent()->PrintLine();
};
};
# get names
results := parser->FindElements("/inventory/section/item/name");
if(results <> Nil) {
Console->Print("names: ")->PrintLine(results->Size());
};
};
}
}
You can’t perform that action at this time.