XQuery Demo

This demo illustrates how to execute an XQuery expression and retrieve the raw XML result.

Below you will find the results to the XQuery expression:

	for $d in document("foo")//folder 
    where $d/@name="Quake" or count($d/file) >= 2

The XML document the XQuery expression is operating on is FileSystem.xml.


Source Code
<%@ Import Namespace="Microsoft.Xml.XQuery" %>
<script language="VB" runat="server">
  Sub Page_Load(sender as Object, e as EventArgs)
     Dim col as New XQueryNavigatorCollection()
     col.AddNavigator(Server.MapPath("FileSystem.xml"), "foo")

     Dim query as String
     query = "for $d in document(""foo"")//folder " & _
             "where $d/@name=""Quake"" or count($d/file) >= 2 " & _
             "return <folder>" & _
             "          <name>{string($d/@name)}</name>" & _
             "          <files>{$d/file}</files>" & _
             "       </folder>"

     Dim expr as New XQueryExpression(query)
     lblXML.Text = (expr.Execute(col)).ToXml()
  End Sub

<asp:Literal runat="server" id="lblXML" />

[Return to the article...]