2011-07-29 3 views
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을 전달할 때 *. 어떻게

답변

2

구문 분석이

어느 XML

가득 문자열을 기대하고 파서로 XML 데이터를 전달할 수 있습니다 (내가 URL을 걸릴 것입니다 생각) XDocument.load을 사용하거나 WebRequest 클래스를 사용하여 XML 문자열을 얻을 그걸 패스

관련 문제