Skip to main content

Update XML Node value using C#

Update the XML document by passing the value to it, updating the specific node of the XML document and replacing the existing value. Here I am updating the date node in the XML document that will be updated while I have entered the text and click the button


update XML using C#

XML format : XMLFile1.xml

<All_batches>
  <Date>10-jan-2016</Date>
</All_batches>

C#

using System;
using System.Web;
using System.Xml;

namespace XMLINS
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Button1_Click(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("D:/WEBROOT/XMLINS/XMLINS/XMLFile1.xml");

            XmlNodeList aDateNodes = doc.SelectNodes("/All_batches/Date");
            foreach (XmlNode aDateNode in aDateNodes)
            {
                XmlAttribute DateAttribute = aDateNode.Attributes["Date"];
                aDateNode.InnerText = TextBox1.Text;
            }
            doc.Save("D:/WEBROOT/XMLINS/XMLINS/XMLFile1.xml");
            Label1.Text = "XML updated Successfully";
        }
    }
}

Comments

  1. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    web designing classes in chennai | web designing training institute in chennai
    web designing and development course in chennai | web designing courses in Chennai
    best institute for web designing in chennai | web designing course with placement in chennai
    Web Designing Class
    web designing course
    best institute for web designing

    ReplyDelete

Post a Comment