2013-02-24 102 views
0

我在使用javascript解析雅虎的天气api时遇到问题。我有一切工作,但我无法弄清楚如何获得多天的数据。我可以得到第一个,但不知道如何获得其他属性。Yahoo天气预报xml

这里是XML部分:

<yweather:forecast day="Sun" date="24 Feb 2013" low="19" high="31" text="Few Snow Showers" code="14"/> 
<yweather:forecast day="Mon" date="25 Feb 2013" low="24" high="35" text="Partly Cloudy" code="30"/> 
<yweather:forecast day="Tue" date="26 Feb 2013" low="33" high="34" text="Rain/Snow Showers" code="5"/> 
<yweather:forecast day="Wed" date="27 Feb 2013" low="31" high="35" text="Snow Showers" code="14"/> 
<yweather:forecast day="Thu" date="28 Feb 2013" low="25" high="33" text="Few Snow Showers" code="14"/> 

而这种代码会得到我的第一个预测

forecastTag = findChild(findChild(effectiveRoot, "item"), "yweather:forecast"); 
day1 = forecastTag.getAttribute("low"); 

所以我怎么为其他日子的数据?我已经尝试过处理yweather:预测为数组[0],[1]等......但它不起作用。我一直在阅读很多关于解析的内容,但无法弄清楚。我是XML新手。

感谢 小号

回答

0

我想通了。

obj.plus1 = request.responseXML.getElementsByTagName("forecast")[1].getAttribute("low"); 
0

您需要通过XML文件来得到这个XML命名空间,

xmlhttp.responseXML.getElementsByTagNameNS('http://xml.weather.yahoo.com/ns/rss/1.0', 'forecast')[1].getAttribute("low");