How to delete specific nodes from an XElement?

How to delete specific nodes from an XElement?

You can try this approach:

var nodes = xRelation.Elements().Where(x => x.Element("Conditions") != null).ToList();

foreach(var node in nodes)
    node.Remove();

Basic idea: you can't delete elements of collection you're currently iterating.
So first you have to create list of nodes to delete and then delete these nodes.

 

 

 

上一篇:XML解析说明


下一篇:哈夫曼树构造以及代码实现