如何从 Linq 查询中保存多个特定的子元素?

XML 文件如下所示


<osm version="0.6" generator="CGImap 0.0.2">

  <bounds minlat="54.0889580" minlon="12.2487570" maxlat="54.0913900" maxlon="12.2524800"/>

  <node id="298884269" lat="54.0901746" lon="12.2482632" user="SvenHRO" uid="46882" visible="true" version="1" changeset="676636" timestamp="2008-09-21T21:37:45Z"/>

  <node id="261728686" lat="54.0906309" lon="12.2441924" user="PikoWinter" uid="36744" visible="true" version="1" changeset="323878" timestamp="2008-05-03T13:39:23Z"/>

  <way id="11103644" visible="true" version="22" changeset="57021161" timestamp="2018-03-09T06:06:21Z" user="thetornado76" uid="1624486">

   <nd ref="5058358201"/>

   <nd ref="5058358200"/>

   <nd ref="459672758"/>

   <nd ref="459672757"/>

   <nd ref="459672756"/>

   <tag k="bicycle" v="no"/>

   <tag k="destination" v="Airport"/>

 </way>

 <way id="11103973" visible="true" version="1" changeset="410956" timestamp="2007-11-05T15:10:28Z" user="DaveHansenTiger" uid="7168">

   <nd ref="98983980"/>

   <nd ref="98983981"/>

   <tag k="tiger:source" v="tiger_import_dch_v0.6_20070809"/>

   <tag k="tiger:tlid" v="116306702"/>

   <tag k="tiger:upload_uuid" v="bulk_upload.pl-bcfe2a6c-15d8-4c58-8cb2-f0d6e1120159"/>

 </way>

</osm>

这是我到目前为止


//Removes the "tag" element from xml

osmFile.Root.Elements().Elements().Where(x => x.Name == "tag").Remove();


//Each iteration of query has the an entire <way> elements and all its children

var query = from c in osmFile.Root.Elements("way")

            select c;

我的问题是,如何才能使遍历查询的每次迭代仅具有特定方式的 nd 元素的所有属性值?


例如,如果我这样做


foreach (var x in query)

    MessageBox.Show(x.ToString());

第一次迭代将显示


5058358201

5058358200

459672758

459672757

459672756

第二个会显示


98983980

98983981

另外,有没有办法在不首先删除所有标签元素的情况下实现这一点?


繁星coding
浏览 147回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP