Chapter 22
548
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()
.
Summary of Contents for DIRECTOR MX-USING DIRECTOR MX
Page 1: ...Using Director MX Macromedia Director MX...
Page 12: ...Contents 12...
Page 156: ...Chapter 4 156...
Page 202: ...Chapter 6 202...
Page 244: ...Chapter 7 244...
Page 292: ...Chapter 10 292...
Page 330: ...Chapter 12 330...
Page 356: ...Chapter 13 356...
Page 372: ...Chapter 14 372...
Page 442: ...Chapter 16 442...
Page 472: ...Chapter 18 472...
Page 520: ...Chapter 19 520...
Page 536: ...Chapter 20 536...
Page 562: ...Chapter 23 562...
Page 566: ...Chapter 24 566...
Page 602: ...Chapter 27 602...