asp.net and XPath: evaluate [] (selection criteria) XPath expression
XPathExpression.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Xml" %>
<!DOCTYPE html>
<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);
XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes(TextBox1.Text.ToString());
foreach (XmlNode node in nodeList)
{
CheckBoxList1.Items.Add(node.FirstChild.Value);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>asp.net and XPath: evaluate [] (selection criteria) XPath expression</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DeepPink; font-style:italic;">XPath Expression Example: [] XPath Expression</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
ForeColor="SaddleBrown"
Text="XPath Expression"
>
</asp:Label>
<asp:TextBox
ID="TextBox1"
runat="server"
Text="//book[@Category='asp.net']/name"
Width="350"
BackColor="Cornsilk"
ForeColor="SaddleBrown"
Font-Bold="true"
>
</asp:TextBox>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Evaluate XPath Expression"
Height="43"
Font-Bold="true"
ForeColor="SaddleBrown"
/>
<br /><br />
<asp:CheckBoxList
ID="CheckBoxList1"
runat="server"
Font-Size="Large"
ForeColor="Crimson"
Font-Names="Comic Sans MS"
>
</asp:CheckBoxList>
</div>
</form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.


- asp.net and XPath: evaluate position XPath expression
- asp.net and XPath: evaluate [last()] XPath expression
- asp.net and XPath: evaluate [last()-1] XPath expression
- XmlNodeList - How to use XmlNodeList in asp.net xml
- XmlDocument SelectNodes() method - How to select nodes in asp.net xml
- XmlDocument SelectSingleNode() method - How to select single node in asp.net xml
- XmlDocument CreateElement()- How to create element using XmlDocument in asp.net
- XmlDocument CreateAttribute() - How to create attribute using XmlDocument
- XmlDocument AppendChild() - How to use AppendChild() method in asp.net
- XmlDocument PrependChild() - How to use PrependChild() method in asp.net