开发者

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 l开发者_开发技巧ong as the tutorial is easy to understand)

Thanks!


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜