C# Xml Manipulation: Remove Node

To remove a node from an xml document just loop through all the nodes using xPath and then call the RemoveChild function like below.

 
XmlDocument xdocLocalFile = new XmlDocument();
 
xdocLocalFile.Load("MyXmlFile.xml");
 
foreach (XmlNode xNodeReplace in
     xdocLocalFile.SelectNodes("root/phunk/firstname"))
{
     xNodeReplace.ParentNode.ParentNode.RemoveChild(xNodeReplace.ParentNode);
}