XmlDocument XmlAttributeCollection in asp.net

XmlDocument XmlAttributeCollection - using XmlAttributeCollection in asp.net
XmlAttributeCollection.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)
    {
        string xmlFilePath = Request.PhysicalApplicationPath + @"App_Data\ITBookList.xml";
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlFilePath);
        
        XmlNode bookNode = xmlDoc.DocumentElement.SelectSingleNode("//book[1]");
        if (bookNode.Attributes != null)
        {
            XmlAttributeCollection attrsCol = bookNode.Attributes;
            foreach (XmlAttribute attr in attrsCol)
            {
                Label1.Text += "<br /> Attribute name: " + attr.Name;
                Label1.Text += "<br /> Attribute value: " + attr.Value+"<br />";
            }
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>XmlDocument XmlAttributeCollection - using XmlAttributeCollection in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:DarkGreen; font-style:italic;">XmlDocument Example: How to use XmlAttributeCollection</h2>
        <hr width="550" align="left" color="Green" />
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            ForeColor="OrangeRed"
            Font-Italic="false"
            Font-Names="Comic Sans MS"
            Text=""
            Font-Size="X-Large"
            >
        </asp:Label>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Get Atrributes Using XmlDocument"
            Height="40"
            Font-Bold="true"
            ForeColor="SeaGreen"
            />
    </div>
    </form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.

   








Related asp.net example