C# Pull XML data from google's weather API

后端 未结 3 646
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 06:36

I\'ve been using this code to try and get data from the google weather API, but I never get even close to pulling out what i want.

My goal is to look at:



        
3条回答
  •  -上瘾入骨i
    2021-01-24 07:04

    using System.Xml.Linq;
    using System.Xml.XPath;
    
    XElement doc = XElement.Load("http://www.google.com/ig/api?weather=london+uk");
    string theCity = doc.XPathSelectElement(@"weather/forecast_information/city").Attribute("data").Value;
    string theTemp = doc.XPathSelectElement(@"weather/current_conditions/temp_c").Attribute("data").Value;
    string theHumid = doc.XPathSelectElement(@"weather/current_conditions/humidity").Attribute("data").Value;
    string theWind = doc.XPathSelectElement(@"weather/current_conditions/wind_condition").Attribute("data").Value;
    
    string resultString = String.Format("City : {0} Temp : {1}c {2} {3}", theCity, theTemp, theHumid, theWind);
    

提交回复
热议问题