views:

227

answers:

3

Hi there

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!

A: 

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

invertedSpear
A: 

That is exactly where the help did not helped me. Namely the Traversing XML structures section.

I will try to ask specific question: I want to traverse XML node with FOR loop and if the node name match specific value I wnat to save it's content to another variable.

Thanks!

dandare
A: 

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.

Niko Nyman