我从一个位置weeb服务获得了这个KML,我需要解析它。我需要读取所有PLACEMARK标签,我只需要从它们的名称纬度和经度。感谢任何帮助。
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Lociraj.net (C) 2010</name>
<StyleMap id="highlighting">
<Pair>
<key>normal</key>
<styleUrl>#normalState</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#highlightedState</styleUrl>
</Pair>
</StyleMap>
<Style id="highlightedState">
<IconStyle>
<scale>1.1</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pal3/icon55.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<scale>1.1</scale>
</LabelStyle>
</Style>
<Style id="normalState">
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pal3/icon63.png</href>
</Icon>
</IconStyle>
</Style>
<Placemark>
<name>Vaša lokacija</name>
<description />
<LookAt>
<longitude>15.976903</longitude>
<latitude>45.813182</latitude>
<altitude>0</altitude>
<range>500</range>
</LookAt>
<Style>
<IconStyle>
<Icon>
<href>http://lociraj.net/img/icon_map_your_location.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>15.976903,45.813182,0</coordinates>
</Point>
</Placemark>
<Folder>
<name>Bankomati</name>
<Placemark>
<name>Raiffeisen</name>
<description>
<![CDATA[ Ilica 1a, Zagreb<br><br>Raiffeisenbank<br>
<b>Udaljenost:</b> 65m<br>
]]>
</description>
<LookAt>
<longitude>15.9761</longitude>
<latitude>45.813</latitude>
<altitude>0</altitude>
<range>500</range>
</LookAt>
<Style>
<IconStyle>
<Icon>
<href>http://lociraj.net/img/icon_map_atm.png</href>
</Icon>
</IconStyle>
</Style>
<ExtendedData xmlns:l="http://lociraj.net">
<l:categoryID>1</l:categoryID>
<l:entryID>1782</l:entryID>
</ExtendedData>
<Point>
<coordinates>15.9761,45.813,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>PBZ</name>
<description>
<![CDATA[ Trg bana J. Jelačića 7, Zagreb<br><br><br>
<b>Udaljenost:</b> 66m<br>
]]>
</description>
<LookAt>
<longitude>15.9777218535</longitude>
<latitude>45.8133623448</latitude>
<altitude>0</altitude>
<range>500</range>
</LookAt>
<Style>
<IconStyle>
<Icon>
<href>http://lociraj.net/img/icon_map_atm.png</href>
</Icon>
</IconStyle>
</Style>
<ExtendedData xmlns:l="http://lociraj.net">
<l:categoryID>1</l:categoryID>
<l:entryID>921</l:entryID>
</ExtendedData>
<Point>
<coordinates>15.9777218535,45.8133623448,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Erste</name>
<description>
<![CDATA[ Ilica bb, Zagreb<br><br>ZET okretište - Črnomerec<br>
<b>Udaljenost:</b> 68m<br>
]]>
</description>
<LookAt>
<longitude>15.976051</longitude>
<latitude>45.81303</latitude>
<altitude>0</altitude>
<range>500</range>
</LookAt>
<Style>
<IconStyle>
<Icon>
<href>http://lociraj.net/img/icon_map_atm.png</href>
</Icon>
</IconStyle>
</Style>
<ExtendedData xmlns:l="http://lociraj.net">
<l:categoryID>1</l:categoryID>
<l:entryID>309</l:entryID>
</ExtendedData>
<Point>
<coordinates>15.976051,45.81303,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Erste</name>
<description>
<![CDATA[ Ilica 1, Zagreb<br><br>Prolaz - Neboder<br>
<b>Udaljenost:</b> 68m<br>
]]>
</description>
<LookAt>
<longitude>15.976051</longitude>
<latitude>45.81303</latitude>
<altitude>0</altitude>
<range>500</range>
</LookAt>
<Style>
<IconStyle>
<Icon>
<href>http://lociraj.net/img/icon_map_atm.png</href>
</Icon>
</IconStyle>
</Style>
<ExtendedData xmlns:l="http://lociraj.net">
<l:categoryID>1</l:categoryID>
<l:entryID>300</l:entryID>
</ExtendedData>
<Point>
<coordinates>15.976051,45.81303,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>ZaBa</name>
<description>
<![CDATA[ Ilica bb, Zagreb<br><br>ZET okretište - Črnomerec<br>
<b>Udaljenost:</b> 68m<br>
]]>
</description>
<LookAt>
<longitude>15.976051</longitude>
<latitude>45.81303</latitude>
<altitude>0</altitude>
<range>500</range>
</LookAt>
<Style>
<IconStyle>
<Icon>
<href>http://lociraj.net/img/icon_map_atm.png</href>
</Icon>
</IconStyle>
</Style>
<ExtendedData xmlns:l="http://lociraj.net">
<l:categoryID>1</l:categoryID>
<l:entryID>1519</l:entryID>
</ExtendedData>
<Point>
<coordinates>15.976051,45.81303,0</coordinates>
</Point>
</Placemark>
</Folder>
</Document>
<kml>
你能帮我解析一下吗
答案 0 :(得分:5)
XDocument xDoc = XDocument.Load(....);
XNamespace ns = "http://www.opengis.net/kml/2.2";
var placemarks = xDoc
.Descendants(ns + "Placemark")
.Select(p => new
{
Name = p.Element(ns+"name").Value,
Longitude = p.Element(ns+"LookAt").Element(ns+"longitude").Value,
Latitude = p.Element(ns+"LookAt").Element(ns+"latitude").Value,
})
.ToArray();