-3

i got this KML from a location weeb service and i need to parse it. i need to get all the PLACEMARK tags read i need just the name latitude and longitude from them. Thx for any help.

<?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>

Can you help me parse this

4

1 回答 1

6
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();
于 2012-09-09T13:15:10.290 回答