Deleting an XML node in C#
-
What are you using to access the XML? How are you storing it?
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
Assuming you are retrieving this in an XmlDocument, just call
DocumentElement.RemoveChild
and pass in the node that you are interested in removing (you actually have to retrieve this node using something like XPath for instance)."WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
If you're using .NET 3.5+
XDocument doc = XDocument.Load( "file.xml" );
var authors = ( from n in doc.Descendants( "author" )
select n );
if (authors != null) {
authors.Remove();
doc.Save( "file.xml" );
}