User Guide
Traversing XML structures 323
Accessing parent and child nodes
The parent() method returns the parent of an XML object.
You can use the ordinal index values of a child list to access specific child objects. For example,
consider an XML object
myXML that has two child properties named book. Each child
property named
book has an index number associated with it:
myXML.book[0]
myXML.book[1]
To access a specific grandchild, you can specify index numbers for both the child and
grandchild names:
myXML.book[0].title[0]
However, if there is only one child of x.book[0] that has the name title, you can omit the
index reference, as follows:
myXML.book[0].title
Similarly, if there is only one book child of the object x, and if that child object has only one
title object, you can omit both index references, like this:
myXML.book.title
You can use the child() method to navigate to children with names based on a variable or
expression, as the following example shows:
var myXML:XML =
<order>
<book>
<title>Dictionary</title>
</book>
</order>;
var childName:String = "book";
trace(myXML.child(childName).title) // output: Dictionary