2009-06-24 8 views
2

気象条件を表示するためにWeather APIから特定の要素を取得しようとしています。まず、<ステーション内のフィード内の< icao>要素であるWeather Stationの名前を取得しようとしています。ここでAPIフィードを使用してC#でXML要素を引き出す

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

どのように私は< ICAO>データを取得することができますか>?このような使用System.Xml.Linq

答えて

8

、:

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) 
関連する問題