Hello,
I have the following XML and I need to extract just two values in the <yweather:condition> tag
code=" "
temp=" "
(current values are code=“34”, temp=“73”, shown in bold below):
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - Athens, GR</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Athens__GR/*http://weather.yahoo.com/forecast/GRXX0004_f.html</link>
<description>Yahoo! Weather for Athens, GR</description>
<language>en-us</language>
<lastBuildDate>Sun, 02 May 2010 11:20 am EEST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Athens" region="" country="Greece" />
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
<yweather:wind chill="73" direction="50" speed="7" />
<yweather:atmosphere humidity="25" visibility="6.21" pressure="30" rising="0" />
<yweather:astronomy sunrise="6:27 am" sunset="8:15 pm" />
<image>
<title>Yahoo Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Athens, GR at 11:20 am EEST</title>
<geo:lat>37.98</geo:lat>
<geo:long>23.74</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Athens__GR/*http://weather.yahoo.com/forecast/GRXX0004_f.html</link>
<pubDate>Sun, 02 May 2010 11:20 am EEST</pubDate>
<yweather:condition text="Fair" **code="34" temp="73"** date="Sun, 02 May 2010 11:20 am EEST" />
<description><img src="http://l.yimg.com/a/i/us/we/52/34.gif"/><br /> <b>Current Conditions:</b><br /> Fair, 73 F<BR /> <BR /><b>Forecast:</b><BR /> Sun - Sunny. High: 78 Low: 59<br /> Mon - Mostly Sunny. High: 78 Low: 60<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Athens__GR/*http://weather.yahoo.com/forecast/GRXX0004_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/></description>
<yweather:forecast day="Sun" date="2 May 2010" low="59" high="78" text="Sunny" code="32" />
<yweather:forecast day="Mon" date="3 May 2010" low="60" high="78" text="Mostly Sunny" code="34" />
<guid isPermaLink="false">GRXX0004_2010_05_02_11_20_EEST</guid>
</item>
</channel>
</rss>
been trying to get to that part and it always gives out “undefined”
trace(weather_xml.firstChild.childNodes[1].childNodes[0].childNodes[12].childNodes[5].childNodes[2].nodeValue);
this breaks down as follows:
weather_xml.firstChild.childNodes[1] // to get to <rss> tag
.childNodes[0] // to get to <channel> tag
.childNodes[12] // to get to <item> tag
.childNodes[5] // to get to <yweather> tag
.childNodes[2] // to get to code=" " attribute
.nodeValue // and show that value
but it doesn’t work at all (all I get is undefined). Does the <?xml version=“1.0” encoding=“UTF-8” standalone=“yes” ?> tag count when I populate nodes or is it commented out? Any ideas what I’m doing wrong?
the XML feed URL is here
http://weather.yahooapis.com/forecastrss?w=946738&u=c