【发布时间】:2011-07-29 16:28:26
【问题描述】:
我试图获取谷歌天气数据如下:
try
{
string cityName = txtCityName.Text;
//Format the google URL with CityName
string weatherURL = string.Format("http://www.google.com/ig/api?weather={0}", cityName);
//Parse the XML URL and get the Data
var weatherXML = XDocument.Parse(weatherURL);
var weatherResult = from weatherDetail in weatherXML.Descendants("current_conditions")
select new currentWeatherCondition
{
condition = ((string)weatherDetail.Element("condition").Attribute("data")).Trim(),
temp = ((string)weatherDetail.Element("temp_c").Attribute("data")).Trim(),
imageURL = ((string)weatherDetail.Element("icon").Attribute("data")).Trim(),
};
}
catch (Exception err)
{
Response.Write(err.Message.ToString());
}
我收到异常 *根级别的数据无效。第 1 行,位置 1。* 因为我没有传递 XML 数据而是 URL。如何将 XML 数据传递到解析器中
【问题讨论】:
标签: c# xml linq linq-to-xml