【发布时间】:2016-08-29 19:22:09
【问题描述】:
我正在尝试用 C# 读取 GML 文件。我想将所有返回的数据存储在一个对象中。到目前为止,我已经能够返回所有数据,但在 3 个单独的对象中:
XDocument doc = XDocument.Load(fileName);
XNamespace gml = "http://www.opengis.net/gml";
// Points
var points = doc.Descendants(gml + "Point")
.Select(e => new
{
POSLIST = (string)e.Element(gml + "pos")
});
// LineString
var lineStrings = doc.Descendants(gml + "LineString")
.Select(e => new
{
POSLIST = (string)e.Element(gml + "posList")
});
// Polygon
var polygons = doc.Descendants(gml + "LinearRing")
.Select(e => new
{
POSLIST = (string)e.Element(gml + "posList")
});
我想创建一个对象,而不是创建 3 个单独的对象,如下所示:
var all = doc.Descendants(gml + "Point")
doc.Descendants(gml + "LineString")
doc.Descendants(gml + "LinearRing")....
但需要一些帮助。先谢谢了。
样本数据:
<gml:Point>
<gml:pos>1 2 3</gml:pos>
</gml:Point>
<gml:LineString>
<gml:posList>1 2 3</gml:posList>
</gml:LineString>
<gml:LinearRing>
<gml:posList>1 2 3</gml:posList>
</gml:LinearRing>
【问题讨论】:
-
Gilad,我添加了示例数据。谢谢。
标签: c# xml linq linq-to-xml gml