ASP.NET XmlDocument - How to select single node

XmlDocument SelectSingleNode() method - How to select single node in asp.net xml
SelectSingleNode.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Xml" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Button1_Click(object sender, System.EventArgs  e)
    {
        Label1.Text = "";
        string xmlPath = Request.PhysicalApplicationPath + @"App_Data\ITBookList.xml";
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlPath);
        XmlNode singleNode = xmlDoc.DocumentElement.SelectSingleNode(TextBox1.Text.ToString());
        Label1.Text = "* "+ singleNode.FirstChild.Value;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>XmlDocument SelectSingleNode() method -  How to select single node in asp.net xml</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Crimson; font-style:italic;">XmlDocument Example: Using SelectSingleNode() Method</h2>
        <hr width="650" align="left" color="DarkSeaGreen" />
        <br /><br />
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            Text=""
            ForeColor="OrangeRed"
            Font-Names="Comic Sans MS"
            Font-Size="X-Large"
            >
        </asp:Label>
        <br /><br /><br />
        <asp:Label 
            ID="Label2" 
            runat="server"
            Font-Bold="true"
            Text="XPath Expression"
            ForeColor="IndianRed"
            >
        </asp:Label>
        <asp:TextBox 
            ID="TextBox1"
            runat="server"
            Text="//book/name"
            ForeColor="Snow"
            Width="200"
            BackColor="DarkSalmon"
            Height="30"
            Font-Bold="true"
            >
        </asp:TextBox>
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Evaluate XPath Expression & Select Node"
            Height="42"
            Font-Bold="true"
            ForeColor="DeepSkyBlue"
            />
        <br /><br />  
        <asp:RadioButtonList 
            ID="RadioButtonList1"
            runat="server"
            Font-Names="Comic Sans MS"
            Font-Size="Large"
            ForeColor="CornflowerBlue"
            BorderColor="LightBlue"
            BorderWidth="1"
            BorderStyle="Dotted"
            >
        </asp:RadioButtonList>
    </div>
    </form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.

   






Related asp.net example