我的xml看起来像:
<kml xmlns="http://earth.google.com/kml/2.0">
<Response>
<name>90210</name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark id="p1">
<address>Beverly Hills, CA 90210, USA</address>
<AddressDetails Accuracy="5"
xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Country>
<CountryNameCode>US</CountryNameCode>
<CountryName>USA</CountryName>
<AdministrativeArea>
<AdministrativeAreaName>CA</AdministrativeAreaName>
<SubAdministrativeArea>
<SubAdministrativeAreaName>Los
Angeles</SubAdministrativeAreaName>
<Locality>
<LocalityName>Beverly Hills</LocalityName>
<PostalCode>
<PostalCodeNumber>90210</PostalCodeNumber>
</PostalCode>
</Locality>
</SubAdministrativeArea>
</AdministrativeArea></Country>
</AddressDetails>
<ExtendedData>
<LatLonBox north="34.1377559" south="34.0642330"
east="-118.3896720" west="-118.4467160" />
</ExtendedData>
<Point>
<coordinates>-118.4104684,34.1030032,0</coordinates>
</Point>
</Placemark>
</Response>
</kml>
我需要扩展数据中的信息,即北/南,东/西的值。
答案 0 :(得分:3)
您还可以深入了解所有节点。但这可能是获取LatLonBox
元素的最简单方法。
var xml = XElement.Parse(xmlString);
var ns = "{http://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),
};
...要深入了解你可以做到的元素......
var extendedData = xml.Element(ns + "Response")
.Element(ns + "Placemark")
.Element(ns + "ExtendedData")
.Element(ns + "LatLonBox");