using System;
using System.Linq;
using System.Xml.Linq;
namespace GoogleWeather
{
public static class GoogleWeatherHelper
{
/// <summary>
/// 获取城市以及省
/// </summary>
/// <param name="xmlWeather">xml数据</param>
/// <returns></returns>
public static string GetCity(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
return forecast_information.Element("city").Attribute("data").Value;
}
/// <summary>
/// 获取中文城市名称
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetPostalCode(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
return forecast_information.Element("postal_code").Attribute("data").Value;
}
/// <summary>
/// 获取预报的日期
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetForecastDate(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
return forecast_information.Element("forecast_date").Attribute("data").Value;
}
/// <summary>
/// 获取湿度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetHumidity(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("current_conditions").First();
return forecast_information.Element("humidity").Attribute("data").Value;
}
/// <summary>
/// 获取风向
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetWindCondition(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("current_conditions").First();
return forecast_information.Element("wind_condition").Attribute("data").Value;
}
/// <summary>
/// 获取今天星期
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTodayWeek(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
return forecast_information.Element("day_of_week").Attribute("data").Value;
}
/// <summary>
/// 获取今天最低温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTodayLow(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
return forecast_information.Element("low").Attribute("data").Value;
}
/// <summary>
/// 获取今天最高温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTodayHight(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
return forecast_information.Element("high").Attribute("data").Value;
}
/// <summary>
/// 获取今天天气图标
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTodayIcon(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
return ExtractFileName(forecast_information.Element("icon").Attribute("data").Value);
}
/// <summary>
/// 获取今天天气情况
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTodayCondition(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
return forecast_information.Element("condition").Attribute("data").Value;
}
/// <summary>
/// 获取明天星期
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTomorrowWeek(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
return forecast_information.Element("day_of_week").Attribute("data").Value;
}
/// <summary>
/// 获取明天最低温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTomorrowLow(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
return forecast_information.Element("low").Attribute("data").Value;
}
/// <summary>
/// 获取明天最高温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTomorrowHight(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
return forecast_information.Element("high").Attribute("data").Value;
}
/// <summary>
/// 获取明天天气图标
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTomorrowIcon(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
return ExtractFileName(forecast_information.Element("icon").Attribute("data").Value);
}
/// <summary>
/// 获取明天天气情况
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTomorrowCondition(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
return forecast_information.Element("condition").Attribute("data").Value;
}
/// <summary>
/// 获取后天星期
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetHouTianWeek(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
return forecast_information.Element("day_of_week").Attribute("data").Value;
}
/// <summary>
/// 获取后天最低温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetHouTianLow(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
return forecast_information.Element("low").Attribute("data").Value;
}
/// <summary>
/// 获取后天最高温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetHouTianHight(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
return forecast_information.Element("high").Attribute("data").Value;
}
/// <summary>
/// 获取后天天气图标
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetHouTianIcon(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
return ExtractFileName(forecast_information.Element("icon").Attribute("data").Value);
}
/// <summary>
/// 获取后天天气情况
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetHouTianCondition(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
return forecast_information.Element("condition").Attribute("data").Value;
}
/// <summary>
/// 获取大后天星期
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetDaHouTianWeek(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
return forecast_information.Element("day_of_week").Attribute("data").Value;
}
/// <summary>
/// 获取大后天最低温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetDaHouTianLow(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
return forecast_information.Element("low").Attribute("data").Value;
}
/// <summary>
/// 获取大后天最高温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetDaHouTianHight(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
return forecast_information.Element("high").Attribute("data").Value;
}
/// <summary>
/// 获取大后天天气图标
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetDaHouTianIcon(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
return ExtractFileName(forecast_information.Element("icon").Attribute("data").Value);
}
/// <summary>
/// 获取大后天天气情况
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetDaHouTianCondition(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
return forecast_information.Element("condition").Attribute("data").Value;
}
private static string ExtractFileName(string fullFileName)
{
string str = fullFileName.Substring(fullFileName.LastIndexOf('/') + 1);
return str.Substring(0, str.LastIndexOf('.')).Replace("cn_", "");
}
}
}
整个天气预报项目源代码的下载地址:
在以后的博文里我会详细讲解这个应用UI方面的实现,毕竟这个应用亮点全在UI上面。我个人是这么理解的,因为功能代码不是很难,UI的效果比较炫。我用了Storyboard来实现了一些效果。
摘自 韩弈风
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Windows Phone 7编程实践—推送通知(剖析推送通知实现架构)
Esri for Window Phone 7(一) 加载BingMap
浅谈ListBox在Windows Phone 7 中的使用
网友评论