0

I am having problems parsing Yahoo's weather api with javascript. I have everything working, but I can't figure out how to get the data for multiple days. I can get the first one, but don't know how to get the other attributes.

Here is the XML part:

<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"/>

And this code will get me the first forecast

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

So how do I get the data for the other days? I have tried treating yweather:forecast as an array [0], [1] etc... but it didn't work. I've been reading a lot about parsing, but just can't figure it out. I am new to XML.

Thanks S

Stu
  • 327
  • 1
  • 3
  • 14

2 Answers2

0

I figured it out.

obj.plus1 = request.responseXML.getElementsByTagName("forecast")[1].getAttribute("low");
Stu
  • 327
  • 1
  • 3
  • 14
0

You need to get this xml's namespace through xml file,

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

Yuan Fu
  • 310
  • 2
  • 14