Selects a collection of elements using an XPath expression. : XPath « XML LINQ « VB.Net






Selects a collection of elements using an XPath expression.

  

Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Linq
Imports System.Collections
Imports System.Collections.Generic
Public Class MainClass

   Public Shared Sub Main()
        Dim root As XElement = _
            <Root>
                <Child1>1</Child1>
                <Child1>2</Child1>
                <Child1>3</Child1>
                <Child2>4</Child2>
                <Child2>5</Child2>
                <Child2>6</Child2>
            </Root>
        Dim list As IEnumerable(Of XElement) = root.XPathSelectElements("./Child2")
        For Each el As XElement In list
            Console.WriteLine(el)
        Next

    End Sub

End Class

   
    
  








Related examples in the same category

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