actionscript 2.0 read XML file
I'm trying to read an XML file with actionscript 2.0
The problem is I can only make my code to read a value of a tag by referencing their position.
e.g.
var currentIcon = myXML.firstChild.firstChild.childNodes[0].firstChild;
How do I retrieve a value from an XMl file by referencing their tag name?
e.g.
var currentIcon = myXML.firstChild.firstChild.childNodes['icon'].firstChild;
Here is my XML file...
<weather>
<current>
<icon>Partly cloudy</icon>
<temphigh>33</temphigh>
<templow>24</templow>
<humhigh>55</humhigh>
<humlow>95</humlow>
</current>
<forecast1>
<day>Monday</day>
<icon>rss_ts2</icon>
<temphigh>33</temphigh>
<templow>24</templow>
</forecast1>
<forecast2>
<day>Tuesday</day>
<icon>rss_ts2</icon>
<temphigh>32</temphigh>
<templow>23</templow>
</forecast2>
<forecast3>
<day>Wednesday</day开发者_如何学Python>
<icon>rss_ts2</icon>
<temphigh>32</temphigh>
<templow>23</templow>
</forecast3>
</weather>
In AS2 you can't directly retrieve a node by name from the childNodes
array (you can do it in AS3 with E4X and dot notation). You should convert your loaded XML
into a native AS2 Object using an XML2Object
parser like this:
http://www.sephiroth.it/weblog/archives/2004/01/xml2object.php
Then you will access your XML
with dot notation like weather.current.icon
.
The link contains the XML2Object
AS2 class and some examples.
This link explains difference about how to handle XML documents in AS2 and AS3:
http://www.thetechlabs.com/tech-tutorials/xml/working-with-xml-e4x-and-actionscript-3/
精彩评论