编程语言
首页 > 编程语言> > How to delete specific nodes from an XElement?

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.

 

 

 

标签:node,specific,How,var,nodes,delete
来源: https://www.cnblogs.com/chucklu/p/14756834.html