How to grab location information in the XML using linq?

You can also drill down though all of the nodes. But this is probably the simplest way to get the LatLonBox element var xml = XElement. Parse(xmlString); var ns = "{earth.google.com/kml/2.0}"; var extendedData = xml.

Descendants(ns + "LatLonBox").First(); var locationBox = new { North = float. Parse(extendedData. Attribute("north").

Value), South = float. Parse(extendedData. Attribute("south").

Value), East = float. Parse(extendedData. Attribute("east").

Value), West = float. Parse(extendedData. Attribute("west").

Value), } to drill down the elements you can do this var extendedData = xml. Element(ns + "Response") . Element(ns + "Placemark") .

Element(ns + "ExtendedData") . Element(ns + "LatLonBox").

You can also drill down though all of the nodes. But this is probably the simplest way to get the LatLonBox element. Var xml = XElement.

Parse(xmlString); var ns = "{earth.google.com/kml/2.0}"; var extendedData = xml. Descendants(ns + "LatLonBox").First(); var locationBox = new { North = float. Parse(extendedData.

Attribute("north"). Value), South = float. Parse(extendedData.

Attribute("south"). Value), East = float. Parse(extendedData.

Attribute("east"). Value), West = float. Parse(extendedData.

Attribute("west"). Value), }; ... to drill down the elements you can do this ... var extendedData = xml. Element(ns + "Response") .

Element(ns + "Placemark") . Element(ns + "ExtendedData") . Element(ns + "LatLonBox").

The xml namespaces can be rather messy. Using the ns + like I did above dramatically simplifies the mess. – Matthew Whited May 17 '10 at 15:04 thanks allot, so you are also using an anonymous class there?

– Blankman May 17 '10 at 15:06 for locationBox yes. You could replace that with a class definition or split it into 4 variables if you want. If you were trying to process a set of elements you could also put that into your LINQ statement.

– Matthew Whited May 17 '10 at 15:10 I should note that there are plenty of places in this code can could throw null reference exceptions. But if you are using this against a known schema you can probably ignore the possible Null values. Each of the chained .

Element(...) methods and the . Value after the . Attribute(...) could each throw a null ref.

– Matthew Whited May 17 '10 at 15:13.

Var xml = XElement. Var extendedData = xml. North = float.

South = float.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions