daniel.sedlacek
daniel.sedlacek

Reputation: 8629

traversing ECMAScript for XML (E4X) - tutorial or example please?

I am using AS3 to traverse through XML but the Flash help is really insufficient here. Do you know any easy-to-read tutorial on how to traverse E4X in for loops or similar?

(I don't think the question is Flash or AS3 specific as long as the tutorial is easy to understand)

Thanks!

Upvotes: 0

Views: 1772

Answers (2)

Niko Nyman
Niko Nyman

Reputation: 1926

With E4X you don't necessarily need to loop through nodes to find specific nodes. You could think of E4X as a search tool for your ndoes. Example:

<addressbook>
    <contact>
        <name/>
        <address/>
        <phone/>
        <phone/>
    </contact>
</addressbook>

So to find all phone nodes, you don't need to loop through the contents of the contacts node. Instead you can ask for all the phone nodes with E4X:

var allPhoneNodes:XMLLIst = myXML.contacts.phone;

You'll get an XMLList with the two phone nodes. If you want to put each phone node into a separate variable, then you could loop through that XMLList just like you would loop through an array, but without the need to test against each node name.

Upvotes: 1

invertedSpear
invertedSpear

Reputation: 11054

This helped me out a lot. Granted it's flex oriented but the e4x syntax is the same.

http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_01.html

Upvotes: 0

Related Questions