ADOBE DIRECTOR 11.0
User Guide
406
To refer to the text data that occurs within a particular tag, use the
text
property. The text is a child node of the tag
that contains it, so you need an additional level of child reference. This script returns the following string, which
appears inside the
e2
tag from the previous XML example:
put gParserObject.child[1].child[2].child[1].text
-- "element 2"
In this example, the
gParserObject
variable refers to the root node of the XML. The
child[1]
refers to the
e1
tag,
which occupies the first level down in the XML’s nested structure. The
child[2]
refers to the second tag within the
e1
tag, which is the
e2
tag. The last
child[1]
refers to the text within the
e2
tag, which is
element 2
. Finally, the
text
property is specified, so the script returns the text of the node rather than any other property of the node.
The fourth child of the
e1
tag is a line of text that reads
here is some text
. This text is a child, as are the XML
tags that precede it. You can get the type of this child the same way you get other children.
The following script returns the type of the fourth child of the
e1
tag:
put gParserObject.child[1].child[4].type
-- #text
The following script returns the text of the fourth child of the
e1
tag:
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
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: