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()
.
Содержание DIRECTOR MX-USING DIRECTOR MX
Страница 1: ...Using Director MX Macromedia Director MX...
Страница 12: ...Contents 12...
Страница 156: ...Chapter 4 156...
Страница 202: ...Chapter 6 202...
Страница 244: ...Chapter 7 244...
Страница 292: ...Chapter 10 292...
Страница 330: ...Chapter 12 330...
Страница 356: ...Chapter 13 356...
Страница 372: ...Chapter 14 372...
Страница 442: ...Chapter 16 442...
Страница 472: ...Chapter 18 472...
Страница 520: ...Chapter 19 520...
Страница 536: ...Chapter 20 536...
Страница 562: ...Chapter 23 562...
Страница 566: ...Chapter 24 566...
Страница 602: ...Chapter 27 602...