7,765
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" ?>
- <xml_api_reply version="1">
- <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
- <forecast_information>
<city data="Beijing, Beijing" />
<postal_code data="Beijing" />
<latitude_e6 data="" />
<longitude_e6 data="" />
<forecast_date data="2011-03-10" />
<current_date_time data="2011-03-10 22:00:00 +0000" />
<unit_system data="US" />
</forecast_information>
- <current_conditions>
<condition data="Clear" />
<temp_f data="61" />
<temp_c data="16" />
<humidity data="Humidity: 12%" />
<icon data="/ig/images/weather/sunny.gif" />
<wind_condition data="Wind: NW at 13 mph" />
</current_conditions>
- <forecast_conditions>
<day_of_week data="Thu" />
<low data="30" />
<high data="55" />
<icon data="/ig/images/weather/sunny.gif" />
<condition data="Clear" />
</forecast_conditions>
- <forecast_conditions>
<day_of_week data="Fri" />
<low data="32" />
<high data="53" />
<icon data="/ig/images/weather/sunny.gif" />
<condition data="Clear" />
</forecast_conditions>
- <forecast_conditions>
<day_of_week data="Sat" />
<low data="41" />
<high data="68" />
<icon data="/ig/images/weather/mostly_sunny.gif" />
<condition data="Mostly Sunny" />
</forecast_conditions>
- <forecast_conditions>
<day_of_week data="Sun" />
<low data="32" />
<high data="57" />
<icon data="/ig/images/weather/mostly_sunny.gif" />
<condition data="Partly Sunny" />
</forecast_conditions>
</weather>
</xml_api_reply>
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Net;
using System.Xml;
private const string _requestURL = @"http://www.google.com/ig/api?weather=";
#region "Event Handlers"
/// <summary>
/// Page_Load runs when the control is loaded
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
string city = Request.QueryString["City"] ?? "Beijing";
ltCity.Text = "Today in " + city;
XmlDocument xmlWeather = GoogleWeatherAPI_Parser(_requestURL + city);
if (xmlWeather != null)
{
XmlNode current_conditions = xmlWeather.SelectSingleNode("xml_api_reply/weather/current_conditions");
ltTemperature.Text = current_conditions.SelectSingleNode("temp_f").Attributes["data"].InnerText;
imgWeather.ImageUrl = string.Format("{0}{1}", "http://www.google.com", current_conditions.SelectSingleNode("icon").Attributes["data"].InnerText);
}
}
/// <summary>
/// Request the weather xml result from the specified URL by GoogleWeatherAPI
/// </summary>
/// <param name="baseUrl"></param>
/// <returns></returns>
private static XmlDocument GoogleWeatherAPI_Parser(string baseUrl)
{
HttpWebRequest GWP_Request;
HttpWebResponse GWP_Response = null;
XmlDocument GWP_XMLdoc = null;
try
{
GWP_Request = (HttpWebRequest)WebRequest.Create(string.Format(baseUrl));
GWP_Request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; en-US; Trident/5.0)";
GWP_Response = (HttpWebResponse)GWP_Request.GetResponse();
GWP_XMLdoc = new XmlDocument();
GWP_XMLdoc.Load(GWP_Response.GetResponseStream());
}
finally
{
GWP_Response.Close();
}
return GWP_XMLdoc;
}
#endregion
<iframe src="http://m.weather.com.cn/m/pn11/weather.htm?id=101010100T " style="border:1px #E6E2ED solid;padding-top:5px;padding-left:5px;" width="490" height="59" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>