Weather APIから特定の要素を取得して、気象条件を表示しようとしています。まず、Weather Stationの名前を取得しようとしています。これは、<station>内のフィードの<icao>要素です。
これが私がプルしようとしているフィードXMLファイルです:http ://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query = 94107
<icao>データ>を取得するにはどうすればよいですか?
Weather APIから特定の要素を取得して、気象条件を表示しようとしています。まず、Weather Stationの名前を取得しようとしています。これは、<station>内のフィードの<icao>要素です。
これが私がプルしようとしているフィードXMLファイルです:http ://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query = 94107
<icao>データ>を取得するにはどうすればよいですか?
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)