2
我試圖讓谷歌的氣象資料如下:得到錯誤而解析XML數據
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數據傳遞到解析器