3

I need to parse the Yahoo Weather RSS feed for a place, like http://weather.yahooapis.com/forecastrss?w=44418&u=c for example, to get the high, low, current temperature and the weather image eg. sun and clouds image, for the current day.

I'd like to do this in Cocoa (Mac).

Any help would be appreciated, thanks!

Seb Jachec
  • 3,003
  • 2
  • 30
  • 56

1 Answers1

4

You have two ways, how you could solve this:

Use a wrapper

If you wan't to solve the problem the easy way, you could use a soloution someone already programmed for you for example this simple wrapper. The problem is that this wrapper just fetches basic things like temperature etc. If you want more informations you'll have to extend the code, but I think that shouldn't be a big problem.

Here is an usage example:

#import "SCYahooWeatherParser.h"
// ...
SCYahooWeatherParser *parser = [[SCYahooWeatherParser alloc] initWithWOEID:woeid weatherUnit: SCWeatherUnitCelcius];
SCYahooWeather *result = [parser parse];
// now you can handle the parameters of result by yourself.

Use a XML Parser

If you wan't you can solve it also the hard, but cleaner way. You can Download the XML from their servers and parse it with a XML Parser. For this I recommend you to first read the documentation of the Yahoo weather API. Than when you know what you're doing I recommend you to use TouchXML for parsing the XML data, because this is a very good XML Parser, which is also use by a lot of people.

evotopid
  • 5,288
  • 2
  • 26
  • 41
  • Thanks a lot for that detailed answer! :) Trying out SCYahooWeather, but as I'm not the best, I'm slightly unsure about how to use it. Should I #import SCWeather.h and then how do I initWithWOEID and all? – Seb Jachec Oct 25 '11 at 17:46
  • First you `#import SCYahooWeatherParser.h` and then you call `[[SCYahooWeatherParser alloc] initWithWOEID:woeid weatherUnit: SCWeatherUnitCelcius];` Than you can generate the result with `SCYahooWeather *result = [parserObject parse];` and than you can access the properties of the result object. – evotopid Oct 25 '11 at 17:52
  • Having a bit of trouble with the SCYahooWeather *result = [parserObject parse]; I get an error - "Use of undeclared identifier 'parserObject'" – Seb Jachec Oct 25 '11 at 18:07
  • Look in the code example, I added now. I think you forgot `...parser = [[SCYahooWeatherParser alloc] ...`. But I'm not sure if that helps you. – evotopid Oct 25 '11 at 18:52
  • Why would you not use the standard NSXMLParser? – OscarWyck Jan 13 '14 at 18:06