I am currently making my first steps in extracting data from an XML i get, where the following link provides the response I get: http://maps.google.com/maps/api/geocode/xml?address=AT,%20Wien
Now I try to get the latitude and logitude of the first element:
string serviceUri = string.Format("http://maps.google.com/maps/api/geocode/xml?address=AT,", location);
XmlDocument doc = new XmlDocument();
XDocument X = XDocument.Load(serviceUri);
var position = X.Element("GeoCodeResponse").Element("result");
var position1= position.Element("geometry").Element("location");
string latitude = position1.Element("lat").Value;
string longitude = position1.Element("lng").Value;
But it seems I missunderstood something from that question which was also answered here: C# extracting data from XML
Please help me understand it a little bit further, br
Try using
if you debug your code in visual studio you will see that
X.Element("GeoCodeResponse")
returns null. And you are trying to useX.Element("")
on null. You can also check null before accessing your root node.