2

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>?

Travis Collins
  • 3,982
  • 3
  • 31
  • 44
LoganFrederick
  • 317
  • 2
  • 8
  • 19

1 Answers1

8

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
  • 868,454
  • 176
  • 1,908
  • 1,964