Link to home
Start Free TrialLog in
Avatar of jdcollins21
jdcollins21

asked on

RSS (Part of the file)

OK, this one probably would be simple if you know what you're doing, but I don't --at all.
Just to give you a bit of background, I'm building a database and I have an embedded web browser (which is where my question comes in). One of the forms is to store location - city/state. I got to thinking it would be cool to add the current weather conditions at the location. One way I thought to go about it is adding a link to yahoo weather. Then I stumbled across the RSS feeds. I can read it, so I have an idea of what's going on, but RSS/XML/Web-Stuff-in-general is not really my thing.

My Question is how do I turn this (the RSS feed for Augusta Georgia):

http://xml.weather.yahoo.com/forecastrss?p=USGA0032&u=f

<?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 - Augusta, GA</title>
  <link>http://us.rd.yahoo.com/dailynews/rss/weather/Augusta__GA/*http://xml.weather.yahoo.com/forecast/USGA0032_f.html</link>
  <description>Yahoo! Weather for Augusta, GA</description>
  <language>en-us</language>
  <lastBuildDate>Fri, 08 Sep 2006 7:53 am EDT</lastBuildDate>
  <ttl>60</ttl>
  <yweather:location city="Augusta" region="GA" country="US" />
  <yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
  <yweather:wind chill="69" direction="40" speed="3" />
  <yweather:atmosphere humidity="84" visibility="805" pressure="30.08" rising="1" />
  <yweather:astronomy sunrise="7:06 am" sunset="7:44 pm" />
- <image>
  <title>Yahoo! Weather</title>
  <width>142</width>
  <height>18</height>
  <link>http://weather.yahoo.com/</link>
  <url>http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
  </image>
- <item>
  <title>Conditions for Augusta, GA at 7:53 am EDT</title>
  <geo:lat>33.47</geo:lat>
  <geo:long>-81.97</geo:long>
  <link>http://us.rd.yahoo.com/dailynews/rss/weather/Augusta__GA/*http://xml.weather.yahoo.com/forecast/USGA0032_f.html</link>
  <pubDate>Fri, 08 Sep 2006 7:53 am EDT</pubDate>
  <yweather:condition text="Cloudy" code="26" temp="69" date="Fri, 08 Sep 2006 7:53 am EDT" />
- <description>
- <![CDATA[
<img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/26.gif" /><br />
 <b>Current Conditions:</b><br />
 Cloudy, 69 F<BR /><BR />
 <b>Forecast:</b><BR />
  Fri - PM Showers. High: 83 Low: 67<br />
  Sat - Partly Cloudy. High: 88 Low: 67<br />
 <br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Augusta__GA/*http://xml.weather.yahoo.com/forecast/USGA0032_f.html">Full Forecast at Yahoo! Weather</a><BR/>
 (provided by The Weather Channel)<br/>
 

  ]]>
  </description>
  <yweather:forecast day="Fri" date="08 Sep 2006" low="67" high="83" text="PM Showers" code="39" />
  <yweather:forecast day="Sat" date="09 Sep 2006" low="67" high="88" text="Partly Cloudy" code="30" />
  <guid isPermaLink="false">USGA0032_2006_09_08_7_53_EDT</guid>
  </item>
  </channel>
  </rss>

 Into....

Current Temperature, Current Weather condition ("Like Partly CLoudy").

That's all I'm really interested in.
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

After a quick google of rss parser javascript, I found something I could quickly hack

<html>
<head>
<script>
function getCurrent() {
  var str = "<B>Current Conditions:</B><BR>" // Cloudy, 73 F<BR><BR>
  var parts = document.getElementById('weather').innerHTML.split(str);
  if (parts.length == 0) return; // not found
  var weatherStr = parts[1].substring(0,parts[1].indexOf('<BR><BR>'))
  document.getElementById('x').innerHTML=weatherStr  
}
</script>
</head>
<body onLoad="getCurrent()">
<div style="display:none" id="weather">
<script src="http://rssxpress.ukoln.ac.uk/lite/viewer/?rss=http%3A%2F%2Fxml.weather.yahoo.com%2Fforecastrss%3Fp%3DUSGA0032%26u%3Df"></script>
</div>
Current weather: <span id="x"></span>

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jdcollins21
jdcollins21

ASKER

Awesome. This is exactly what I was after. Thanks mplungjan
Please be aware it will only work as long as
a) the site http://rssxpress.ukoln.ac.uk/lite/viewer/ 
continues to handle the url and their CSS that processes the rss does not change
b) yahoo.com's weather reply does not change

If it does, let me know.

Michel
Will do. I was already thinking about that and looking at alternatives. But you put me on the right path.