Click here to Skip to main content
11,707,167 members (50,155 online)
Click here to Skip to main content

Tagged as

XmlElement. Delete current node

, 27 Nov 2009 CPOL 14.4K 3
Rate this:
Please Sign up or sign in to vote.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

db_developer
Database Developer Freelancer
Ukraine Ukraine
MS SQL Server Database Developer with 7+ years experience

Technologies/languages: Business Intelligence, SQL, MDX, VBA, SQL Server, Analysis Services (SSAS), Reporting services (SSRS), Integration Services (SSIS), DataWarehouse.
Also: economic background.

Feel free to contact me for rates and details.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 28 Nov 2009
Article Copyright 2009 by db_developer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid