Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
#~
# compile: obc -src xml_2 -lib xml,gen_collect
# 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]")<XmlElement>;
if(results <> Nil) {
Standard->Print("items: ")->PrintLine(results->Size());
};
# get all prices
results := parser->FindElements("/inventory/section/item/price")<XmlElement>;
if(results <> Nil) {
each(i : results) {
element := results->Get(i)->As(XmlElement);
element->GetContent()->PrintLine();
};
};
# get names
results := parser->FindElements("/inventory/section/item/name")<XmlElement>;
if(results <> Nil) {
Standard->Print("names: ")->PrintLine(results->Size());
};
};
}
}