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

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.