XPathNodeIterator - Usnig XPathNodeIterator in asp.net xml
XPathNodeIterator.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html>
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
RadioButtonList1.ForeColor = Color.DarkSalmon;
RadioButtonList1.Font.Name = "Comic Sans MS";
RadioButtonList1.Font.Italic = true;
RadioButtonList1.BorderColor = Color.Pink;
RadioButtonList1.BorderWidth = 1;
RadioButtonList1.BorderStyle = BorderStyle.Dotted;
}
}
void Button1_Click(object sender, System.EventArgs e)
{
RadioButtonList1.Items.Clear();
string xmlPath = Request.PhysicalApplicationPath + @"App_Data\ITBookList.xml";
XPathDocument xPathDoc = new XPathDocument(xmlPath);
XPathNavigator xPathNavigator = xPathDoc.CreateNavigator();
XPathExpression xPathExpr = xPathNavigator.Compile(TextBox1.Text);
XPathNodeIterator nodes = xPathNavigator.Select(xPathExpr);
while (nodes.MoveNext())
{
RadioButtonList1.Items.Add(nodes.Current.Value);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>XPathNodeIterator - Usnig XPathNodeIterator in asp.net xml</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkSeaGreen; font-style:italic;">XPathNodeIterator Example: Using XPathNodeIterator</h2>
<hr width="575" align="left" color="DarkSeaGreen" />
<asp:RadioButtonList
ID="RadioButtonList1"
runat="server"
>
</asp:RadioButtonList>
<br /><br />
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
Text="XPath Expression"
ForeColor="DeepPink"
>
</asp:Label>
<asp:TextBox
ID="TextBox1"
runat="server"
Text="//book/author"
ForeColor="Snow"
Width="325"
BackColor="DeepPink"
Height="35"
Font-Bold="true"
>
</asp:TextBox>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Evaluate XPath Expression"
Height="40"
Font-Bold="true"
ForeColor="IndianRed"
/>
</div>
</form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.

