User Guide
322 Working with XML
Traversing XML structures
One of the powerful features of XML is its ability to provide complex, nested data via a linear
string of text characters. When you load data into an XML object, ActionScript parses the
data and loads its hierarchical structure into memory (or it sends a run-time error if the XML
data is not well formed).
The operators and methods of the XML and XMLList objects make it easy to traverse the
structure of XML data.
Use the dot (.) operator and the descendent accessor (..) operator to access child properties of
an XML object. Consider the following XML object:
var myXML:XML =
<order>
<book ISBN="0942407296">
<title>Baking Extravagant Pastries with Kumquats</title>
<author>
<lastName>Contino</lastName>
<firstName>Chuck</firstName>
</author>
<pageCount>238</pageCount>
</book>
<book ISBN="0865436401">
<title>Emu Care and Breeding</title>
<editor>
<lastName>Case</lastName>
<firstName>Justin</firstName>
</editor>
<pageCount>115</pageCount>
</book>
</order>
The object myXML.book is an XMLList object containing child properties of the myXML object
that have the name
book. These are two XML objects, matching the two book properties of
the
myXML object.
The object
myXML..lastName is an XMLList object containing any descendent properties
with the name
lastName. These are two XML objects, matching the two lastName of the
myXML object.
The object
myXML.book.editor.lastName is an XMLList object containing any children
with the name
lastName of children with the name editor of children with the name book
of the
myXML object: in this case, an XMLList object containing only one XML object (the
lastName property with the value "Case").