Here is my XML
,
<A>
<B id="ABC">
<C name="A" />
<C name="B" />
</B>
<X>
<B id="ZYZ">
<C name="A" />
<C name="B" />
</B>
</X>
</A>
I'm using following code to remove <X>
node without deleting its descents/childrens,
XDocument doc = XDocument.Load("D:\\parsedXml.xml");
doc.Descendants("A").Descendants("X").Remove();
But is removing entire <X>
block.
Expected output :
<A>
<B id="ABC">
<C name="A" />
<C name="B" />
</B>
<B id="ZYZ">
<C name="A" />
<C name="B" />
</B>
</A>
var x = doc.Root.Element("X");
x.Remove();
doc.Root.Add(x.Elements());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With