User Guide
Chapter 22548
Accessing attributes
Some XML tags contain attributes with values. Use the Lingo attributeName and
attributeValue properties to access the attributes of tags that have values. In the previous XML
example, the first tag nested inside the
e1 tag is called tagName and has two attributes called
attr1 and attr2.
The following Lingo uses the
attributeName property to return the name of the first attribute of
the tag called
tagName, which is the first child of the e1 tag:
put gParserObject.child[1].child[1].attributeName[1]
-- "attr1"
The following Lingo uses the attributeValue property with an integer to return the value of the
first attribute of the tagName tag:
put gParserObject.child[1].child[1].attributeValue[1]
-- "val1"
The following Lingo uses the attributeValue property with a string to return the value of the
attr1 attribute:
put gParserObject.child[1].child[1].attributeValue["attr1"]
-- "val1"
The following Lingo uses the count function with the attributeName property to return the
number of attributes in the first child of the
e1 tag:
put gParserObject.child[1].child[1].attributeName.count
-- 2
Parser objects and XML nodes
As described in earlier sections, the parser object in the gParserObject variable stores the root
of the parsed tree of the XML document. An XML node is a node within the tree. The root
node is like an XML node because almost all the operations on XML nodes can be applied to
the root node.
In the previous XML example, the root of the tree is an XML element node named "ROOT OF
XML DOCUMENT" that has no attributes and one child (the
e1 tag). You can get the same
information about the root node as for any of the child nodes.
The following Lingo returns the root node’s type, name, and number of children:
put gParser.type, gParser.name, gParser.count(#child)
-- #element "ROOT OF XML DOCUMENT" 1
The main difference between the root node and its child nodes is that there are several Lingo
commands that apply to the entire XML document and operate on the root node only. These
commands include
doneParsing(), getError(), ignoreWhiteSpace(), makeList(),
parseString(), and parseURL().