使用 C# Linq to XML 解析 GML 数据
我知道这很可能是非常基本的,并且被问过一千次,但由于某种原因我就是无法让它工作。
我有一个如下所示的 gml 文件:
<?xml version='1.0' encoding='UTF-8'?>
<schema
xmlns='http://www.w3.org/2000/10/XMLSchema'
xmlns:gml='http://www.opengis.net/gml'
xmlns:xlink='http://www.w3.org/1999/xlink'
xmlns:xsi='http://www.w3.org/2000/10/XMLSchema-instance'
xsi:schemaLocation='http://www.opengis.net/gml/feature.xsd'>
<gml:Polygon srsName='http://www.opengis.net/gml/srs/epsg.xml#4283'>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coord>
<gml:X>152.035953</gml:X>
<gml:Y>-28.2103190007845</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>152.035957</gml:X>
<gml:Y>-28.2102020007845</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>152.034636</gml:X>
<gml:Y>-28.2100120007845</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>152.034617</gml:X>
<gml:Y>-28.2101390007845</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>152.035953</gml:X>
<gml:Y>-28.2103190007845</gml:Y>
</gml:coord>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</schema>
我需要做的就是从每个 gml:coord 节点读取 X 和 Y。我正在使用 C# 3.0 和 LINQ,所以它应该很容易,但我尝试的所有内容都只返回空结果。
我只用 VB 做过 xml 解析,所以目前 C# 方式对我来说有点陌生。
谢谢, 内森
I know this is most likly very basic and been asked a thousand times but for some reason I just can't get it to work.
I have a gml file that looks like the following:
<?xml version='1.0' encoding='UTF-8'?>
<schema
xmlns='http://www.w3.org/2000/10/XMLSchema'
xmlns:gml='http://www.opengis.net/gml'
xmlns:xlink='http://www.w3.org/1999/xlink'
xmlns:xsi='http://www.w3.org/2000/10/XMLSchema-instance'
xsi:schemaLocation='http://www.opengis.net/gml/feature.xsd'>
<gml:Polygon srsName='http://www.opengis.net/gml/srs/epsg.xml#4283'>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coord>
<gml:X>152.035953</gml:X>
<gml:Y>-28.2103190007845</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>152.035957</gml:X>
<gml:Y>-28.2102020007845</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>152.034636</gml:X>
<gml:Y>-28.2100120007845</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>152.034617</gml:X>
<gml:Y>-28.2101390007845</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>152.035953</gml:X>
<gml:Y>-28.2103190007845</gml:Y>
</gml:coord>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</schema>
All I need to be able to do is read the X and Y from each gml:coord node. I am using C# 3.0 and LINQ so it should be easy but everything I try just returns empty results.
I have only done xml parsing in VB so the C# way is a bit foreign to me at the moment.
Thanks,
Nathan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是您没有包含名称空间。这是一个简短但完整的程序,显示了所有坐标:
My guess is that you haven't included the namespace. Here's a short but complete program which shows all the coords: