Parses an XML document
OperationsCode example:
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());
};
};
Default constructor
New(string:String)
Name | Type | Description |
---|---|---|
string | String | XML to parse |
Default constructor
New(buffer:Char[])
Name | Type | Description |
---|---|---|
buffer | Char[] | XML to parse |
Finds matching XML elements using xpath like syntax. Supports 'first()', 'last()' and '[cdata]' functions.
method : public : FindElements(path:String) ~ Vector<XmlElement>
Name | Type | Description |
---|---|---|
path | String | search string |
Type | Description |
---|---|
Vector<XmlElement> | matching XML elements |
Gets the XML encoding
method : public : GetEncoding() ~ String
Type | Description |
---|---|
String | XML encoding |
Get the current parsing error
method : public : GetError() ~ String
Type | Description |
---|---|
String | current parsing error |
Gets the root XML element
method : public : GetRoot() ~ XmlElement
Type | Description |
---|---|
XmlElement | root XML element |
Gets XML version
method : public : GetVersion() ~ String
Type | Description |
---|---|
String | XML version |
Parses the XML document
method : public : Parse() ~ Bool
Type | Description |
---|---|
Bool | true if parsed, false otherwise |
Parses an XmlElement text
function : TextToElement(text:String) ~ XmlElement
Name | Type | Description |
---|---|---|
text | String | JSON text |
Type | Description |
---|---|
XmlElement | root document element |
Produces an XML string representation of the document
method : public : ToString() ~ String
Type | Description |
---|---|
String | string representation of the document |