ASP.NET XPath Expression - evaluate [last()]

asp.net and XPath: evaluate [last()] XPath expression
XPathExpression.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)
    {
        Label2.Text = "";
        string xmlPath = Request.PhysicalApplicationPath + @"App_Data\ITBookList.xml";
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlPath);
        XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes(TextBox1.Text.ToString());
        foreach (XmlNode node in nodeList)
        {
            Label2.Text += node.FirstChild.Value;
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>asp.net and XPath: evaluate [last()] XPath expression</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:SaddleBrown; font-style:italic;">XPath Expression Example: [last()] XPath Expression</h2>
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            ForeColor="DarkCyan"
            Text="XPath Expression"
            >
        </asp:Label>
        <asp:TextBox 
            ID="TextBox1"
            runat="server"
            Text="//book[last()]/name"
            Width="350"
            ForeColor="DarkCyan"
            BackColor="Cyan"
            Height="35"
            Font-Bold="true"
            >
        </asp:TextBox>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Height="43"
            Text="Evaluate XPath Expression"
            Font-Bold="true"
            ForeColor="DarkCyan"
            />
        <br /><br />  
        <asp:Label 
            ID="Label2"
            runat="server"
            ForeColor="Maroon"
            Font-Bold="true"
            Font-Size="Large"
            Font-Names="Comic Sans MS"
            >
        </asp:Label>          
    </div>
    </form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.

   






Related asp.net example