Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 解析XML数据时出错_C#_Xml_Linq_Linq To Xml - Fatal编程技术网

C# 解析XML数据时出错

C# 解析XML数据时出错,c#,xml,linq,linq-to-xml,C#,Xml,Linq,Linq To 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); //Pars

我试图获取谷歌天气数据,如下所示:

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数据传递到解析器中

Parse需要一个填充XML的字符串

要么使用XDocument.load(我认为它将采用url),要么使用webrequest获取xml字符串并将其传入