我是 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 包含每个节点。对于这些查询的价值,这些查询也是空的:
Dim foo = Kml.Descendants("Document")
Dim foo = Kml.Descendants("Folder")
有人可以指出我正确的方向吗?链接到好的 Linq to XML 教程的加分点——我在网上找到的那些在非常简单的场景中停止。