Pulling XML Elements in C# Via an API Feed -
To demonstrate the weather condition, I am trying to pull some elements from a weather API. First of all, I'm trying to catch the name of the weather station, which is & lt; In the feed inside the IoCo> element & lt; Station>.
Here is the feed XML file that I am trying to drag:
I & lt; ICO> Data>?
Use System.Xml.Linq
, like this: < / P>
XDocument.Load (@ "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=94107") .Root .Element ("Element ( "Airport"). Element ("Station") Element ("ICO"). Value
Or, if you want to get value for all the station,
< Pre> XDocument.Load (@ "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=94107") .Root .Element ("Element" ("Station" Select "Elements" ("Station"). (S = & gt; s.Element ("Ioco"). Value)
Comments
Post a Comment