Thursday, March 6, 2008

Reading weather data from www.yr.no

Thanks to Sjur for the tip about the weather service at www.yr.no, which actually has a web service publishing pure xml data.

To access a weather service for your favourite location, look it up through the yr.no search and add "Varsel.xml" to the URL.

Access from C# / .Net:

// Load xml from URL
string feedURL = @"http://www.yr.no/sted/Norge/Oslo/Oslo/Oslo/Varsel.xml";
XmlDocument xDoc = new XmlDocument();
xDoc.Load(feedURL);

// Get forecast information
XmlNodeList forecast = xDoc.GetElementsByTagName("forecast");


// Read into dataset
DataSet ds = new DataSet();
StringReader readerStream = new StringReader(forecast[0].OuterXml);
ds.ReadXml(readerStream);

And you have an untyped dataset full of weather information.

Thank you yr.no.

(check the next post for how to read the data with Linq)

0 Comments:

Post a Comment

<< Home