Extensions::XPathSelectElements Method (XNode^, String^)
Selects a collection of elements using an XPath expression.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
public: [ExtensionAttribute] 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.
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.
This example produces the following output:
<Child2>4</Child2> <Child2>5</Child2> <Child2>6</Child2>
Available since 3.5
Silverlight
Available since 4.0