
424
Chapter 19: Using the XML Parser Xtra
This script returns the text of the fourth child of the
e1
tag, as shown in the following example:
put gParserObject.child[1].child[4].text
-- "
here is some text
"
The text element includes the white space for Return, Space, and Tab characters as well as the
string
"
here is some text
"
.
You can use the script
count
method to determine the number of children that exist at a
particular level of the XML structure. The following script returns the number of children at the
2nd level in the previous XML example:
put gparser.child[1].child.count
-- 4
Accessing attributes
Some XML tags contain attributes with values. Use the
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 script 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 script 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 script 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 script uses the
count
method 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.
Summary of Contents for DIRECTOR MX 2004-USING DIRECTOR
Page 1: ...DIRECTOR MX 2004 Using Director...
Page 16: ...16 Chapter 1 Introduction...
Page 82: ...82 Chapter 3 Sprites...
Page 98: ...98 Chapter 4 Animation...
Page 134: ...134 Chapter 5 Bitmaps...
Page 242: ...242 Chapter 10 Sound and Synchronization...
Page 274: ...274 Chapter 11 Using Digital Video...
Page 290: ...290 Chapter 12 Behaviors...
Page 302: ...302 Chapter 13 Navigation and User Interaction...
Page 334: ...334 Chapter 15 The 3D Cast Member 3D Text and 3D Behaviors...
Page 392: ...392 Chapter 16 Working with Models and Model Resources...
Page 418: ...418 Chapter 18 Movies in a Window...
Page 446: ...446 Chapter 22 Managing and Testing Director Projects...