views:

242

answers:

1

I'm attempting to pull certain elements from a Weather API to display weather conditions. First, I'm trying to grab the Weather Station name, which is the < icao > element in the feed inside the < station>.

Here is the feed XML file I'm trying to pull from: http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=94107

How can I obtain the the < icao > data>?

+6  A: 

Use System.Xml.Linq, like this:

XDocument.Load(@"http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=94107")
 .Root
 .Element("nearby_weather_stations")
 .Element("airport")
 .Element("station")
 .Element("icao").Value

Or, if you want to get the values for all of the stations,

XDocument.Load(@"http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=94107")
 .Root
 .Element("nearby_weather_stations")
 .Element("airport")
 .Elements("station")
 .Select(s => s.Element("icao").Value)
SLaks