I am attempting to read data from an XML file in C# (for Windows Phone). I return the following XML file:
private async void GetCoords2() { string requestURI = "https://maps.googleapis.com/maps/api/geocode/xml?address=Donegal%20Town&key=XXX"; HttpWebRequest request = HttpWebRequest.Create(requestURI) as HttpWebRequest; WebResponse response = await request.GetResponseAsync(); using (var reader = new StreamReader(response.GetResponseStream())) { responseContent = reader.ReadToEnd(); // Do anything with you content. Convert it to xml, json or anything. ParseContent(); } }
I am attempting to retrieve the first instance of latitude and longtitude from the XML file, which is available here: https://maps.googleapis.com/maps/api/geocode/xml?address=Donegal%20Town&key=XXX
I have followed several samples from online, and previous projects I have worked on, but none seem to be working.
How can I retrieve the first instance of lat and lon?
Thanks.
Edit: had to remove key from URL, posted screenshot of image instead.
UPDATE: The code I currently have.
void ParseContent() { XmlReader xmlReader = XmlReader.Create(responseContent); List<string> aTitle = new List<string>(); // Add as many as attributes you have in your "stop" element XmlReader reader = XmlReader.Create(responseContent); reader.ReadToDescendant("location"); while (reader.Read()) { reader.MoveToFirstAttribute(); reader.ReadToFollowing("lat"); string latX = reader.ReadElementContentAsString(); reader.ReadToFollowing("lng"); string lngX = reader.ReadElementContentAsString(); //reader.ReadToFollowing("Subcategory"); //string subcategory = reader.ReadElementContentAsString(); //reader.ReadToFollowing("Favourited"); //Boolean favourited = Boolean.Parse(reader.ReadElementContentAsString()); //basketxml.Add(new Pets(name, category, subcategory, description, dob, stock, price, image, id, favourited)); MessageBox.Show(latX + " / " + lngX); } }
No comments:
Post a Comment