我在使用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新手。
感謝 小號