Remove xml nodes using Linq to XML

lagertez

New Member
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 \[code\]N level\[/code\].
  • 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:\[code\]<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>\[/code\]In above xml when \[code\]taskId=2\[/code\] is removed, it's sub-tasks namely \[code\]Id = 3\[/code\] should be removed. Since \[code\]3\[/code\] is removed it's subtasks \[code\]4\[/code\] and \[code\]5\[/code\] should be removed as well.
 
Back
Top