.net 使用LINQ删除XML文档中的重复值
如何删除XML文档中重复的属性值 这是一个示例XML,它有1个重复的名称值作为3种方式-假爱: 使用扩展方法而不是Distinct。此方法将从文档中删除所有选定的节点。C代码:.net 使用LINQ删除XML文档中的重复值,.net,xml,vb.net,linq,duplicates,.net,Xml,Vb.net,Linq,Duplicates,如何删除XML文档中重复的属性值 这是一个示例XML,它有1个重复的名称值作为3种方式-假爱: 使用扩展方法而不是Distinct。此方法将从文档中删除所有选定的节点。C代码: xdoc.Root.Elements("Song") .GroupBy(s => (string)s.Element("Name")) .SelectMany(g => g.Skip(1)) // select all nodes from group except first one
xdoc.Root.Elements("Song")
.GroupBy(s => (string)s.Element("Name"))
.SelectMany(g => g.Skip(1)) // select all nodes from group except first one
.Remove();
VB
使用扩展方法而不是Distinct。此方法将从文档中删除所有选定的节点。C代码:
xdoc.Root.Elements("Song")
.GroupBy(s => (string)s.Element("Name"))
.SelectMany(g => g.Skip(1)) // select all nodes from group except first one
.Remove();
VB
xdoc.Root.Elements("Song")
.GroupBy(s => (string)s.Element("Name"))
.SelectMany(g => g.Skip(1)) // select all nodes from group except first one
.Remove();
xdoc.Root.<Song> _
.GroupBy(Function(s) CStr(s.Element("Name"))) _
.SelectMany(Function(g) g.Skip(1)) _
.Remove()