Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
actionscript 2.0读取XML文件_Xml_Actionscript - Fatal编程技术网

actionscript 2.0读取XML文件

actionscript 2.0读取XML文件,xml,actionscript,Xml,Actionscript,我正在尝试使用actionscript 2.0读取XML文件 问题是我只能让代码通过引用标记的位置来读取标记的值 e、 g。 var currentIcon=myXML.firstChild.firstChild.childNodes[0].firstChild 如何通过引用XMl文件的标记名从XMl文件中检索值 e、 g。 var currentIcon=myXML.firstChild.firstChild.childNodes['icon'].firstChild 这是我的XML文件 &l

我正在尝试使用actionscript 2.0读取XML文件

问题是我只能让代码通过引用标记的位置来读取标记的值

e、 g。
var currentIcon=myXML.firstChild.firstChild.childNodes[0].firstChild

如何通过引用XMl文件的标记名从XMl文件中检索值

e、 g。
var currentIcon=myXML.firstChild.firstChild.childNodes['icon'].firstChild

这是我的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>

多云
33
24
55
95
星期一
rss_ts2
33
24
星期二
rss_ts2
32
23
星期三
rss_ts2
32
23

在AS2中,您不能直接从
子节点
数组中按名称检索节点(您可以在AS3中使用E4X和点表示法进行检索)。您应该使用
XML2Object
解析器将加载的
XML
转换为本机AS2对象,如下所示:

然后您将使用点符号访问您的
XML
,如
weather.current.icon

该链接包含
XML2Object
AS2类和一些示例

此链接解释了在AS2和AS3中如何处理XML文档的区别: