asp.net and XPath: evaluate // (relative path) 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)
{
BulletedList1.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)
{
BulletedList1.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 // (relative path) XPath expression</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy; font-style:italic;">XPath Expression Example: // XPath Expression</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
ForeColor="SeaGreen"
Text="XPath Expression"
>
</asp:Label>
<asp:TextBox
ID="TextBox1"
runat="server"
Text="//book/name"
BackColor="PaleGoldenrod"
Width="300"
Font-Bold="true"
ForeColor="SeaGreen"
>
</asp:TextBox>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="Evaluate XPath Expression"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
ForeColor="SaddleBrown"
/>
<br />
<asp:BulletedList
ID="BulletedList1"
runat="server"
BulletStyle="LowerRoman"
Font-Bold="true"
Font-Size="Large"
Font-Italic="true"
ForeColor="OrangeRed"
>
</asp:BulletedList>
</div>
</form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.


- asp.net and XSLT - How to pass parameters to XSLT document
- asp.net and XSLT - Using XslCompiledTransform Class in asp.net
- Using System.Xml, System.Xml.Xsl, System.Xml.XPath Namespace in asp.net
- XmlDocument - Load XmlDocument from XmlReader and use XPath
- 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 CreateXmlDeclaration()- How to use CreateXmlDeclaration() method
- XmlDocument CreateElement()- How to create element using XmlDocument in asp.net
- XmlDocument CreateAttribute() - How to create attribute using XmlDocument