Update xml node example:

The following sample will Update existing node with new values in xml file.

In UpdateXMLNode.aspx file:

<table>
    <tr>
    <td align="right">VisitorNum:</td>
    <td><asp:TextBox ID="tbVstrNum" runat="server" ></asp:TextBox></td>
    </tr>
    <tr>
    <td align="right">FName:</td>
    <td><asp:TextBox ID="tbFName" runat="server" ></asp:TextBox></td>
    </tr>
    <tr>
    <td align="right">LName:</td>
    <td><asp:TextBox ID="tbLName" runat="server" ></asp:TextBox></td>
    </tr>
    <tr>
    <td align="right">Age:</td><td><asp:TextBox ID="tbAge" runat="server" ></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td align="right">Gender:</td><td><asp:TextBox ID="tbGender" runat="server" ></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td></td>
    <td>
    <asp:Button ID="btnUpdatePatient" Text="UpdatePatient" runat="server"  OnClick="btnUpdatePat_Click"/>
     </td>
     </tr>
    </table>

In UpdateXMLNode.aspx.cs:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;

public partial class UpdateXMLNode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnUpdatePat_Click(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        string filePath = Server.MapPath("Patients.xml");
        doc.Load(filePath);
        XmlNode patient = doc.SelectSingleNode("Patients/Patient[VistorNum=" + tbVstrNum.Text + "]");
        //The above code will identify the matched patient node.
        XmlNodeList list = patient.ChildNodes;
        foreach (XmlNode node in list)
        {
            switch (node.Name)
            {
                case "FName":
                    node.InnerText = tbFName.Text;
                    break;
                case "LName":
                    node.InnerText = tbLName.Text;
                    break;
                case "Age":
                    node.InnerText = tbAge.Text;
                    break;
                case "Gender":
                    node.InnerText = tbGender.Text;
                    break;
                default:
                    break;
            }
        }
        doc.Save(filePath);
    }
}

Xml file structure:

Create an Xml file with the name Patients.xml as shown below.
<?xml version="1.0" encoding="utf-8"?>
<Patients>
  <Patient type="IP">
    <VistorNum>134</VistorNum>
    <FName>Maha</FName>
    <LName>Lakshmi</LName>
    <Age>89</Age>
    <Gender>FeMale</Gender>
  </Patient>
  <Patient type="OP">
    <VistorNum>135</VistorNum>
    <FName>Kasturi</FName>
    <LName>Rangaiah</LName>
    <Age>88</Age>
    <Gender>Male</Gender>
  </Patient>
  <Patient>
    <VistorNum>138</VistorNum>
    <FName>Rajeev</FName>
    <LName>Ranjan</LName>
    <Age>98</Age>
    <Gender>Male</Gender>
  </Patient>
</Patients>