Fairly new to Linq to XML How does one remove xml node( recursively using relation ) and save the document.
Structure of the xml cannot be altered as it comes from service.Below is the xml from a tasks service. Every task can have nested tasks for which there might be one or more nested tasks. Nesting is intended to be upto N level.
-
When one of parent tasks are removed using linq to xml how do i remove all of it’s children?
-
How do i know all the nodes where successfully removed?
Xml:
<Tasks>
<Task ID="1">Clean the Room</Task>
<Task ID="2">Clean the Closet</Task>
<Task ID="3" ParentId="2">Remove the toys</Task>
<Task ID="4" ParentId="3">Stack action Figures on Rack</Task>
<Task ID="5" ParentId="3">Put soft toys under bed</Task>
</Tasks>
In above xml when taskId=2 is removed, it’s sub-tasks namely Id = 3 should be removed. Since 3 is removed it’s subtasks 4 and 5 should be removed as well.
I’m going to assume that with the xml:
If
Task ID=2is removed, here is one solution:Result: