我是LINQ to XML新手,还是KML新手。那就和我一起

我的目标是从KML文件中提取单个地标。我的KML由此开始:

<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="http://earth.google.com/kml/2.0">
  <name>Concessions</name>
  <visibility>1</visibility>
  <Folder>
    <visibility>1</visibility>
    <Placemark>
      <name>IN920211</name>
      <Style>
        <PolyStyle>
          <color>80000000</color>
        </PolyStyle>
      </Style>
      <Polygon>
        <altitudeMode>relativeToGround</altitudeMode>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>11.728374,1.976421,0 11.732967,1.965322,0 11.737225,1.953161,0 11.635858,1.940812,0 11.658102,1.976874,0 11.728374,1.976421,0 </coordinates>
          </LinearRing>
        </outerBoundaryIs>
      </Polygon>
    </Placemark>
    <Placemark>
    ...

据我所知:

    Dim Kml As XDocument = XDocument.Load(Server.MapPath("../kmlimport/ga.kml"))
    Dim Placemarks = From Placemark In Kml.Descendants("Placemark") _
         Select Name = Placemark.Element("Name").Value

到目前为止没有任何好处-Kml.Descendants(“Placemark”)给我一个空的枚举。该文档已正确加载-因为KML.Descendants包含每个节点。对于这些查询而言,它们的值(value)也是空的:
Dim foo = Kml.Descendants("Document")
Dim foo = Kml.Descendants("Folder")

有人可以指出我正确的方向吗?指向优质Linq到XML教程的链接的加分点-我在网上发现的链接停在非常简单的场景中。

最佳答案

这在C#中对我有用:

XDocument doc = XDocument.Load(@"TheFile.kml");

var q = doc.Descendants().Where(x => x.Name.LocalName == "Placemark");

关于vb.net - Linq to XML for KML?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/151521/

10-17 01:14