XPathNavigator Compile() – How to compile Expression in asp.net XML


- <%@ Page Language=“C#” AutoEventWireup=“true” %>
- <%@ Import Namespace=“System.Xml” %>
- <%@ Import Namespace=“System.Xml.XPath” %>
- <%@ Import Namespace=“System.Drawing” %>
- <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
- <script runat=“server”>
- void Page_Load(object sender, System.EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- BulletedList1.ForeColor = Color.DeepPink;
- BulletedList1.Font.Name = “Comic Sans MS”;
- BulletedList1.Font.Size = FontUnit.Large;
- BulletedList1.BulletStyle = BulletStyle.LowerRoman;
- }
- }
- void Button1_Click(object sender, System.EventArgs e)
- {
- BulletedList1.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())
- {
- BulletedList1.Items.Add(nodes.Current.Value);
- }
- }
- </script>
- <html xmlns=“http://www.w3.org/1999/xhtml” >
- <head id=“Head1″ runat=“server”>
- <title>XPathNavigator Compile() - How to compile XPathExpression in asp.net xml</title>
- </head>
- <body>
- <form id=“form1″ runat=“server”>
- <div>
- <h2 style=“color:IndianRed; font-style:italic;”>XPathNavigator Example: How To Use Compile() Method</h2>
- <hr width=“575″ align=“left” color=“Pink” />
- <asp:BulletedList
- ID=“BulletedList1″
- runat=“server”
- >
- </asp:BulletedList>
- <br /><br />
- <asp:Label
- ID=“Label2″
- runat=“server”
- Font-Bold=“true”
- Text=“XPath Expression”
- ForeColor=“IndianRed”
- >
- </asp:Label>
- <asp:TextBox
- ID=“TextBox1″
- runat=“server”
- Text=“//book/name”
- ForeColor=“Snow”
- Width=“325″
- BackColor=“IndianRed”
- 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>


No comments:
Post a Comment