【问题标题】:Getting error while Parsing the XML data解析 XML 数据时出错
【发布时间】: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


    【解决方案1】:

    Parse 期待一个用 XML 填充的字符串

    要么使用 XDocument.load(我认为它需要一个 url),要么使用 webrequest 获取 xml 字符串并将其传递给

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-28
      • 2015-11-18
      • 1970-01-01
      相关资源
      最近更新 更多