Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 使用LINQ删除XML文档中的重复值_.net_Xml_Vb.net_Linq_Duplicates - Fatal编程技术网

.net 使用LINQ删除XML文档中的重复值

.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

如何删除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
    .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()