Delete a specific xml node in xml file using C#

protected void DeleteXmlNode(int selectedIndex)
    XmlDocument docXml = new XmlDocument();
    docXml.Load(Server.MapPath(@"App_Data\myXmlFile.xml")); //locate and load xml file in application
    XmlNode node = docXml.DocumentElement.ChildNodes.Item(selectedIndex); //locate specific index node
    node.ParentNode.RemoveChild(node); //remove node
    docXml.Save(Server.MapPath(@"App_Data\mynewXmlFile.xml")); //save file

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.