Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / XML

Delete an XML node using the node name

4.78/5 (2 votes)
23 Aug 2011CPOL 44.6K  
How to delete an XML node using its name.

Using xml.linq we can delete a node from XML in C#.


C#
XDocument XMLDoc = XDocument.Load(path);
XElement elment = (from xml1 in XMLDoc.Descendants("Node")
                   select xml1).FirstOrDefault();
elment.Remove();
XMLDoc.Save(path);

License

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