asp.net and XPath: evaluate [position()<5] 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)
{
RadioButtonList1.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)
{
RadioButtonList1.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 [position()<5] XPath expression</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:HotPink; font-style:italic;">XPath Expression Example: [position()<5] XPath Expression</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
Text="XPath Expression"
ForeColor="DarkSeaGreen"
>
</asp:Label>
<asp:TextBox
ID="TextBox1"
runat="server"
Text="//book[position()<5]/name"
ForeColor="Snow"
Width="350"
BackColor="DarkSeaGreen"
Height="35"
Font-Bold="true"
>
</asp:TextBox>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Evaluate XPath Expression"
Height="42"
Font-Bold="true"
ForeColor="DarkSeaGreen"
/>
<br /><br />
<asp:RadioButtonList
ID="RadioButtonList1"
runat="server"
ForeColor="OrangeRed"
Font-Names="Comic Sans MS"
Font-Italic="true"
Font-Size="Large"
>
</asp:RadioButtonList>
</div>
</form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.


- asp.net and XPath: evaluate [position()>4] XPath expression
- asp.net and XPath: evaluate [element>value] XPath expression
- asp.net and XPath: evaluate [@*] (elements with any attribute) XPath expression
- XmlNodeList - How to use XmlNodeList in asp.net xml
- XmlDocument SelectSingleNode() method - How to select single node in asp.net xml
- XmlDocument CreateAttribute() - How to create attribute using XmlDocument
- XmlDocument PrependChild() - How to use PrependChild() method in asp.net
- XmlDocument - How to update (change) node data (value) programmatically in asp.net
- XmlDocument XmlAttributeCollection - using XmlAttributeCollection in asp.net