我想使用雅虎天气API。但之前的API已经被授权。我如何在我的C#代码中使用雅虎天气RSS?

问题描述:

我想使用雅虎天气API。但之前的API已经被授权。我如何在我的C#代码中使用雅虎天气RSS? 我一直在尝试使用此:我想使用雅虎天气API。但之前的API已经被授权。我如何在我的C#代码中使用雅虎天气RSS?

https://query.yahooapis.com/v1/public/yql?q=select%20%20from%20weather.forecast%20where%20woeid%3D1915035%20and%20u%3D%27c%27&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

,但它似乎回到NullXmlNode

+0

提供代码,请。 –

private void GetWeather() 
{ 
    string query = String.Format("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D1915035%20and%20u%3D%27c%27&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"); 
    XmlDocument wData = new XmlDocument(); 
    wData.Load(query); 

    XmlNamespaceManager manager = new XmlNamespaceManager(wData.NameTable); 
    manager.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); 

    XmlNode channel = wData.SelectSingleNode("rss").SelectSingleNode("channel");//exception here 
    XmlNodeList nodes = wData.SelectNodes("rss/channel/item/yweather:forecast", manager); 

    Temperature = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["temp"].Value; 
    Condition = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["text"].Value; 
    Humidity = channel.SelectSingleNode("yweather:atmosphere", manager).Attributes["humidity"].Value; 
    WindSpeed = channel.SelectSingleNode("yweather:wind", manager).Attributes["speed"].Value; 
    Town = channel.SelectSingleNode("yweather:location", manager).Attributes["city"].Value; 
    TPCond = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["text"].Value; 
    TPHigh = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["high"].Value; 
    TPLow = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["low"].Value;   
}