I created an XElement with a node that has XML, as shown below.
I want to delete all the "Rule" nodes if they contain the "conditions" node.
I create a for loop as below, but it does not delete my nodes
foreach (XElement xx in xRelation.Elements()) { if (xx.Element("Conditions") != null) { xx.Remove(); } }
Example:
<Rules effectNode="2" attribute="ability" iteration="1"> <Rule cause="Cause1" effect="I"> <Conditions> <Condition node="1" type="Internal" /> </Conditions> </Rule> <Rule cause="cause2" effect="I"> <Conditions> <Condition node="1" type="External" /> </Conditions> </Rule> </Rules>
How to delete all nodes "Rule" if they contain "conditions" node?
source share