How to remove xml node using RemoveChild

I have searched lots of web site for deleting xml node , but after searching lots of web site i able to delete the node. Now i can show you how to do that .

XML File

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <Page>
    <Id>1</Id>
    <Name>Default.aspx</Name>
    <Title>Client Management System </Title>
  </Page>
  <Page>
    <Id>2</Id>
    <Name>Login.aspx</Name>
    <Title>Login Page</Title>
   </Page>
  <Page>
    <Id>3</Id>
    <Name>About.aspx</Name>
    <Title>About Page</Title>
   </Page>
  <Page>
 </configuration>

C# Code

               string node_no = 2;

                string SeoXmlFile = MapPath("SeoXml.xml");
                //create new instance of XmlDocument
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(SeoXmlFile);
               
                XmlNode rootNode = xmlDoc.DocumentElement;

                //XmlNodeList nodes = xmlDoc.SelectNodes("configuration");


                rootNode.RemoveChild(rootNode.ChildNodes[4]);
                xmlDoc.Save(SeoXmlFile);

                LoadSeoGrid();

 

After Delete The node the Xml file is

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <Page>
    <Id>1</Id>
    <Name>Default.aspx</Name>
    <Title>Client Management System </Title>
  </Page>
  <Page>
    <Id>2</Id>
    <Name>Login.aspx</Name>
    <Title>Login Page</Title>
   </Page>
 </configuration>

 

Related Posts

  • How to add a new XML node to file
  • How to remove xml elements using RemoveChild()?
  • Insert Html Tags Inside XML Node
  • Insert in to MySQL with ASP.NET – Part 2
  • Insert in to MySQL with ASP.NET – Part 1
I am Muhammod Arifur Rahman, CEO and founder of Learneveryday.net I worked on asp.net mainly. My second skill language is php and wordpress. I am also work on jquery. I love to work with new problem and feel happy when solve. www.smartdatasoft.com is my own company.

Got something to say? Go for it!

*

 
More in Xml (2 of 4 articles)