五天预测错误

时间:2015-08-25 05:55:20

标签: c# xml

以下是获取天气的完整代码

public string Sunset;
public string Sunrise;
string Temperature;
string Condition;
string Humidity;
string WindSpeed;
string Town;
string TFCond;
string TFHigh;
string TFLow;

private void GetWeather()
{
    string query = String.Format("http://weather.yahooapis.com/forecastrss?w=" + woeid + "&u=c");
    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");
    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;

    Day1 = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["temp"].Value;

    Day2 = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["temp"].Value;

    Day3 = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["temp"].Value;

    Sunset = channel.SelectSingleNode("yweather:astronomy", manager).Attributes["sunset"].Value;

    Sunrise = channel.SelectSingleNode("yweather:astronomy", manager).Attributes["sunrise"].Value;
}

我现在可以帮助我,我已经提供了完整的天气代码吗?

0 个答案:

没有答案