search xml node example:

The following sample will search xml node in xml file.

In SearchXMLNode.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="btnSearchPatient" Text="SearchPatient" runat="server"  OnClick="btnSearchPat_Click"/>
     </td>
     </tr>
    </table>

In SearchXMLNode.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 SearchNode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSearchPat_Click(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        string loc = Server.MapPath("Patients.xml");
        doc.Load(loc);
        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)
        {
            XmlNodeList cnList = node.ChildNodes;
            //node.
            Hashtable htPatInfo = new Hashtable();
            foreach (XmlNode cnode in cnList)
            {
                htPatInfo.Add(cnode.Name, cnode.InnerText);
            }
            DisplayData(htPatInfo); 
        }
    }
    private void DisplayData(Hashtable htPatData)
    {
        tbGender.Text = htPatData["Gender"].ToString();
        tbLName.Text = htPatData["LName"].ToString();
        tbFName.Text = htPatData["FName"].ToString();
        tbAge.Text = htPatData["Age"].ToString();
    }
}

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>