[英]actionscript 2.0 read XML file
I'm trying to read an XML file with actionscript 2.0 我正在尝试使用ActionScript 2.0读取XML文件
The problem is I can only make my code to read a value of a tag by referencing their position. 问题是我只能使我的代码通过引用其位置来读取标签的值。
eg var currentIcon = myXML.firstChild.firstChild.childNodes[0].firstChild;
例如var currentIcon = myXML.firstChild.firstChild.childNodes[0].firstChild;
How do I retrieve a value from an XMl file by referencing their tag name? 如何通过引用XMl文件的标记名来检索值?
eg var currentIcon = myXML.firstChild.firstChild.childNodes['icon'].firstChild;
例如var currentIcon = myXML.firstChild.firstChild.childNodes['icon'].firstChild;
Here is my XML file... 这是我的XML文件...
<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>
<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). 在AS2中,您不能直接从childNodes
数组中按名称检索节点(您可以在AS3中使用E4X和点表示法进行操作)。 You should convert your loaded XML
into a native AS2 Object using an XML2Object
parser like this: 您应该使用XML2Object
解析器将加载的XML
转换为本地AS2对象,如下所示:
http://www.sephiroth.it/weblog/archives/2004/01/xml2object.php http://www.sephiroth.it/weblog/archives/2004/01/xml2object.php
Then you will access your XML
with dot notation like weather.current.icon
. 然后,您将使用点符号(如weather.current.icon
访问XML
。
The link contains the XML2Object
AS2 class and some examples. 该链接包含XML2Object
AS2类和一些示例。
This link explains difference about how to handle XML documents in AS2 and AS3: 此链接说明了有关如何在AS2和AS3中处理XML文档的区别:
http://www.thetechlabs.com/tech-tutorials/xml/working-with-xml-e4x-and-actionscript-3/ http://www.thetechlabs.com/tech-tutorials/xml/working-with-xml-e4x-and-actionscript-3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.