我是一个LINQ to
XML新手,也是一个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,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到XML教程的链接的奖励点 – 我在网上找到的那些在非常简单的场景中停止.
这适用于C#:
XDocument doc = XDocument.Load(@"TheFile.kml"); var q = doc.Descendants().Where(x => x.Name.LocalName == "Placemark");