2

Weather APIから特定の要素を取得して、気象条件を表示しようとしています。まず、Weather Stationの名前を取得しようとしています。これは、<station>内のフィードの<icao>要素です。

これが私がプルしようとしているフィードXMLファイルです:http ://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query = 94107

<icao>データ>を取得するにはどうすればよいですか?

4

1 に答える 1

8

System.Xml.Linq次のように使用します。

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

または、すべてのステーションの値を取得する場合は、

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)
于 2009-06-24T19:50:02.487 に答える