65.9K
CodeProject is changing. Read more.
Home

XmlElement. Delete current node

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.75/5 (3 votes)

Nov 26, 2009

CPOL
viewsIcon

27060

I was thinking that it is a simple task "select nodes using XPath expression and then to delete them from XML Document", but after I spent a couple of hours ... My fault was I searched for something likes 'Remove current node', 'Delete active node', 'Detach node from tree', etc. Way to delete...

I was thinking that it is a simple task "select nodes using XPath expression and then to delete them from XML Document", but after I spent a couple of hours ... My fault was I searched for something likes 'Remove current node', 'Delete active node', 'Detach node from tree', etc.

Way to delete node is removing of it from its parent node:

			XmlNodeList nodes = xmlDoc.SelectNodes("//node");			
			foreach (XmlNode node in nodes)
			{
				node.ParentNode.RemoveChild(node);
			}

The Meat of the tip is code line node.ParentNode.RemoveChild(node) which does removing XML node.