Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is what I could come up with.</p> <p>For the number of hits. Use the GridView row count. Indeed the GetXmlDocument.ChildNodes.Count always return the number of lexical items, not the number of hits whan the XPath expression is applied.</p> <p>Test XML</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;lexique&gt; &lt;item acronym="WPF" value="Windows Presentation Foundation"/&gt; &lt;item acronym="SO" value="StackOverflow"/&gt; &lt;/lexique&gt; </code></pre> <p>Minimalist ASP.net Page</p> <pre><code>&lt;%@ Page Language="vb" AutoEventWireup="false" CodeBehind="xmlgrid.aspx.vb" Inherits="WebApplication1.WebForm1" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:Label ID="FilterLabel" runat="server" Text="Acronym starting with:"&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="FilterTextBox" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:XmlDataSource ID="LexiqueXmlDataSource" runat="server" DataFile="~/lexique.xml"&gt; &lt;/asp:XmlDataSource&gt; &lt;asp:GridView ID="LexiqueGrid" runat="server" AllowSorting="true" BorderStyle="Groove"&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Acronym"&gt; &lt;ItemTemplate&gt; &lt;%# XPath("/lexique/item/@acronym")%&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Value"&gt; &lt;ItemTemplate&gt; &lt;%# XPath("/lexique/item/@value")%&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:Label ID="Hits" runat="server" Text="Acronyms found"&gt;&lt;/asp:Label&gt; &lt;asp:Button ID="Submit" runat="server" Text="Search" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Code Behind</p> <pre><code>Public Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim XPath As String If String.IsNullOrEmpty(FilterTextBox.Text) Then XPath = "/lexique/item" Else XPath = "/lexique/item[starts-with(@acronym, '" + FilterTextBox.Text + "')]" End If LexiqueXmlDataSource.XPath = XPath LexiqueXmlDataSource.DataBind() LexiqueGrid.DataSource = LexiqueXmlDataSource LexiqueGrid.DataBind() Hits.Text = "Selected " &amp; LexiqueGrid.Rows.Count &amp; " out of " &amp; LexiqueXmlDataSource.GetXmlDocument.ChildNodes.Count &amp; "Acronyms loaded." End Sub End Class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload