Export (0) Print
Expand All

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)

[ExtensionAttribute]
public:
static IEnumerable<XElement^>^ XPathSelectElements(
	XNode^ node, 
	String^ expression
)

Parameters

node
Type: System.Xml.Linq::XNode

The XNode on which to evaluate the XPath expression.

expression
Type: System::String

A String that contains an XPath expression.

Return Value

Type: System.Collections.Generic::IEnumerable<XElement>
An IEnumerable<T> of XElement that contains the selected elements.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type XNode. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

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.

No code example is currently available or this language may not be supported.

This example produces the following output:

<Child2>4</Child2>
<Child2>5</Child2>
<Child2>6</Child2>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft