Click here to Skip to main content
Click here to Skip to main content

Weather Forecast with Yahoo! Weather RSS Feed

By , 13 Jul 2009
 

Screenshot - Weather_forecast.jpg

Introduction

Every time I wanted to use a weather forecast for my site, I found it too confusing. Each method I found had problems - some of the weather forecast Web services did not work properly. Eventually I noticed that Yahoo! has an RSS for its weather forecast. I decided to make a program to use that in my site and I created a class for it! I hope it will be useful for others who want to have weather forecasts in their programs.

Yahoo! Weather RSS feed

The Yahoo! Weather RSS feed enables you to get up-to-date weather information for your location. You can save this feed in My Yahoo! or your favorite feed aggregate. You can also incorporate the RSS data into your own Web site or client application. The Yahoo! Weather RSS feed is a dynamically-generated feed that is based on zip code or Location ID.

RSS Request

The Yahoo! Weather RSS feed request follows simple HTTP GET syntax: start with a base URL and then add parameters and values after a question mark (?). Multiple parameters are separated by an ampersand (&). There are two parameters for Weather RSS:

  • p for location
  • u for degrees units (Fahrenheit or Celsius)

RSS Response

The Yahoo! Weather RSS feed is an XML document that conforms to RSS 2.0 specifications. RSS is an XML document containing: a single channel element representing the feed, several elements containing metadata about the feed itself, and one or more item elements describing individual items within the feed. You can find all information about these elements on the Yahoo Developer page here. As it is represented in an XML document, we can convert it to classes by XML Serialization in .NET.

Understanding XML Serialization in the .NET Framework

XML Serialization enables you to convert common language runtime objects into XML documents or streams, and vise versa. XML Serialization makes it possible to convert XML documents into such a meaningful format that all programming languages can process the converted documents without any difficulty. You don't need to know much about XML Serialization to use this code, but it can help you to change or customize it yourself.

Using the Code

Using this code is as simple as making an instance of it and then sending its required parameters (Yahoo! Weather RSS parameters) to its constructor. The first parameter is US zip code or Location ID. The second one is Units for temperature. Send "f" for Fahrenheit or "c" for Celsius and then you can use it! Like this:

'//For example we send "IRXX0018" for Location ID of Tehran, and we want 
'//Units for temperature as Fahrenheit
 Dim t As New YahooWeatherForecast("IRXX0018", "f")
 Response.Write(t.rss.channel.item.description)
 Response.Write(t.rss.channel.item.forecast.high)
 Response.Write(t.rss.channel.item.forecast.low)

History

  • 25th April, 2007: Initial post
  • 15th May, 2007 - Updated source file
  • 3rd May, 2008: Updated source file

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Farhad Siasar Djahantighi 2
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionWhy cannot I download the code?membertdyso_zmh3 May '12 - 19:32 
GeneralMy vote of 5membermahnazfekri26 Jul '11 - 0:19 
QuestionAdding Severe Weather Watch or Warnings or Both to your Library?membertimnboys25 Jun '10 - 10:09 
How to I Add Severe Weathers Watch or Warnings or Both to your Library
GeneralMy vote of 1mvpDave Kreskowiak16 Jul '09 - 8:59 
QuestionAdding the Dew Point to your library?memberrspercy6014 Jul '09 - 15:32 
AnswerRe: Adding the Dew Point to your library?memberFarhad Siasar Djahantighi14 Jul '09 - 18:12 
QuestionHeat Index?memberrspercy609 Jul '09 - 15:46 
AnswerRe: Heat Index?.....Answermemberrspercy6010 Jul '09 - 11:17 
QuestionHow to get startedmembermark lonsbury4 Apr '09 - 5:04 
AnswerRe: How to get startedmemberFarhad Siasar Djahantighi10 Jul '09 - 18:57 
QuestionI got a Ctype Error in VWD 2008 Express. What's wrong with the CType?membercslamsg23 Oct '08 - 22:52 
Generalget tomorrows weathermemberbflosabre9111 Aug '08 - 9:55 
GeneralYahoo! Weather mashupmembervirtuPIC12 May '08 - 20:21 
General"Error in XML Document"membersayeo872 May '08 - 5:07 
GeneralRe: "Error in XML Document"memberDan Suthar2 May '08 - 22:56 
GeneralRe: "Error in XML Document"memberarashk12 May '08 - 22:58 
GeneralRe: "Error in XML Document"memberMCofer11 May '08 - 8:30 
GeneralRe: "Error in XML Document"memberMCofer11 May '08 - 10:20 
GeneralRe: "Error in XML Document" ...the fixmemberrspercy609 Jul '09 - 11:52 
GeneralInput string was not in a correct formatmembersuresh00820 Mar '08 - 18:33 
GeneralRe: Input string was not in a correct formatmemberarashk123 Mar '08 - 21:45 
GeneralMulti Day Forecastmemberbuster9526 Feb '08 - 16:52 
AnswerRe: Multi Day Forecastmemberfranzil8 May '08 - 2:19 
GeneralYahoo URL has changed to http://weather.yahooapis.com/forecastrssmembermichael knopf14 Feb '08 - 4:12 
GeneralVB Express 2005memberSteve_5523 Oct '07 - 7:21 
QuestionHow to change the language to Chinese ?membertpang1328 Aug '07 - 0:37 
GeneralAstronomy Classmemberkfwbird26 Jul '07 - 13:45 
AnswerRe: Astronomy Classmemberarashk127 Jul '07 - 9:30 
GeneralRe: Astronomy Classmemberkfwbird30 Jul '07 - 10:57 
QuestionPicturesmemberosilala2 Jul '07 - 6:46 
AnswerRe: Picturesmemberrspercy6010 Jul '09 - 13:13 
AnswerRe: PicturesmemberFarhad Siasar Djahantighi10 Jul '09 - 18:53 
GeneralUnable to connect to the remote servermemberCuu22 May '07 - 13:26 
GeneralRe: Unable to connect to the remote servermemberarashk122 May '07 - 18:55 
GeneralRe: Unable to connect to the remote servermemberCuu23 May '07 - 5:06 
GeneralRe: Unable to connect to the remote servermemberJap Santi29 May '07 - 18:07 
Question2 forecast in RSS but only one in the lib?memberducgerman20 May '07 - 22:58 
Question??memberSteve Noll9 May '07 - 2:53 
AnswerRe: ?? [modified]memberarashk19 May '07 - 2:55 
GeneralRe: ??memberSteve Noll9 May '07 - 3:36 
GeneralRe: ??memberarashk111 May '07 - 20:22 
GeneralRe: ??memberSteve Noll13 May '07 - 23:54 
GeneralRe: ??memberarashk114 May '07 - 18:46 
GeneralRe: ??memberSteve Noll15 May '07 - 0:14 
GeneralWhats WrongmemberSteve Noll9 May '07 - 0:08 
GeneralRe: Whats Wrongmemberarashk19 May '07 - 0:40 
GeneralFacing Some ProblemmemberRehan Hussain1 May '07 - 20:10 
GeneralRe: Facing Some Problemmemberarashk15 May '07 - 21:27 
GeneralVery usefullmemberTOL-WEBMASTER1 May '07 - 11:19 
GeneralRe: Very usefullmemberarashk11 May '07 - 19:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 13 Jul 2009
Article Copyright 2007 by Farhad Siasar Djahantighi 2
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid