Loop through the query results and display the information to the screen. : XPath « XML LINQ « VB.Net






Loop through the query results and display the information to the screen.

   

Imports System
Imports System.Xml.Linq
Imports System.Xml.XPath

    Public Class MainClass
        Public Shared Sub Main()
            Dim employees As XElement = XElement.Load("EmployeesAndTasks.xml")

            Dim xpathQuery = employees.XPathSelectElements("/Employee/Tasks/Task")
            For Each task In xpathQuery
                Console.WriteLine("{0,-15} - {1} ({2})", task.Parent.Parent.<Name>.Value, task.<Name>.Value, task.<Description>.Value)
            Next
        End Sub

    End Class

   
    
    
  








Related examples in the same category

1.Use XPath to get the tasks for each employee.
2.Selecting node by XPath
3.Evaluates an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.
4.Selects a collection of elements using an XPath expression.
5.XPathExpression Class provides a typed class that represents a compiled XPath expression.
6.Selects a collection of elements using an XPath expression.