我有这个 XML 结构:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>My Work</name>
<Placemark>
<name>Main Building</name>
<Polygon>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>Office 1</name>
<Polygon>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>
这继续……
我需要为每个人选择建筑物“名称”并将其存储在列表中。我写了这段代码:
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections.Generic;
namespace dsdsdsds
{
public class Building
{
public string BuildingName { get; set; }
}
class MainClass
{
public static void Main(string[] args)
{
List<Building> buildingNames =
(from e in XDocument.Load("buildings.kml").Root
.Elements("Document")
select new Building
{
BuildingName = (string)e.Element("name")
}).ToList();
foreach (var e in buildingNames)
{
Console.WriteLine(e);
}
}
}
}
但是,它似乎不想输出任何东西,我无法找出我哪里出错了。有人可以帮我吗?
谢谢