How to use XmlNodeList in asp.net xml

XmlNodeList - How to use XmlNodeList in asp.net xml
UsingXmlNodeList.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)
    {
        CheckBoxList1.Items.Clear();
        string xmlPath = Request.PhysicalApplicationPath + @"App_Data\ITBookList.xml";
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlPath);
        try
        {
            XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("//book/name");
            foreach (XmlNode node in nodeList)
            {
                CheckBoxList1.Items.Add(node.FirstChild.Value);
            }
        }
        catch (XmlException xmlEx)
        {
            Response.Write("Xml Exception: " + xmlEx.Message.ToString());
        }
        catch (Exception ex)
        {
            Response.Write("Error occured: " + ex.Message.ToString());
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>XmlNodeList - How to use XmlNodeList in asp.net xml</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green; font-style:italic;">XmlNodeList Example: How To Use XmlNodeList</h2>
        <asp:Label 
            ID="Label1" 
            runat="server"
            Text="XPath Expression //book/name"
            ForeColor="DeepSkyBlue"
            Font-Size="Large"
            Font-Names="Comic Sans MS"
            >
        </asp:Label>
        <asp:CheckBoxList 
            ID="CheckBoxList1"
            runat="server"
            ForeColor="HotPink"
            BorderColor="LawnGreen"
            BorderStyle="Dotted"
            BorderWidth="1"
            Font-Names="Comic Sans MS"
            Font-Size="Large"
            >
        </asp:CheckBoxList>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Evaluate XPath Expression and Select Nodes"
            Height="42"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.

   






Related asp.net example