XPathSelectElements Method (XNode, String)

Extensions.XPathSelectElements Method (XNode, String)


Selects a collection of elements using an XPath expression.

Namespace:   System.Xml.XPath
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

Public Shared Function XPathSelectElements (
	node As XNode,
	expression As String
) As IEnumerable(Of XElement)


Type: System.Xml.Linq.XNode

The XNode on which to evaluate the XPath expression.

Type: System.String

A String that contains an XPath expression.

Return Value

Type: System.Collections.Generic.IEnumerable(Of XElement)

An IEnumerable(Of T) of XElement that contains the selected elements.

Although the ordering of returned collections is not specified in the XML XPath Language 1.0 Recommendation, this extension method returns nodes in document order.

Note that nodes are returned in document order even when you use a reverse axis, such as preceding-sibling or ancestor-or-self.

The following example creates a small XML tree and uses XPathSelectElements to select a set of elements.

Dim root As XElement = _
Dim list As IEnumerable(Of XElement) = root.XPathSelectElements("./Child2")
For Each el As XElement In list

This example produces the following output:


Universal Windows Platform
Available since 10
.NET Framework
Available since 3.5
Available since 4.0
Return to top
© 2015 Microsoft