asp.net XPathNavigator – How to use XPathNavigator in asp.net xml


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


No comments:
Post a Comment