Imports Microsoft.Xml.XQuery
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'First, we need to create XQueryNavigatorCollection instance:
        Dim xcol As New XQueryNavigatorCollection()

        'Then we need to link the xml data file to our instance, AddNavigator method`s first input will be the path of the data file and second one is the alias of that file. This alias will be useful while writing our XQuery to point out our data file.
        Dim FileName As String = Application.StartupPath & "\Filesystem.xml"

        xcol.AddNavigator(FileName, "doc")

        'We are writing our XQuery and assign it to a string value, as you can see I used "doc" alias that points Data.xml file:
        'After assigning our query to a string we give this string to XQueryExpression class`s constructor, by doing this step our query will be ready to be executed:

        Dim xepr As New XQueryExpression(txtQuery.Text)

        'To execute our query and get the output from it we are just writing:
        Dim result As String

        result = xepr.Execute(xcol).ToXml

        txtResult.Text = result
        'and getting the result to string result variable. By getting the result you can do whatever you want with it. You can just display it as it is or by assigning it to a DataSet you can give to it more usable scope in your project.


    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtQuery.Text = "for $row in document(""doc"")/filesystem/drive/folder/file " & vbCrLf & _
            "return " & vbCrLf & _
            "$row"

    End Sub
End Class
