Extensions.XPathSelectElements Selects a collection of elements using an XPath expression. : XPath « XML « C# / C Sharp






Extensions.XPathSelectElements Selects a collection of elements using an XPath expression.

    
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml.XPath;
using System.IO;
public class MainClass{
   public static void Main(){
      XElement root = new XElement("Root",
          new XElement("Child1", 1),
          new XElement("Child1", 2),
          new XElement("Child1", 3),
          new XElement("Child2", 4),
          new XElement("Child2", 5),
          new XElement("Child2", 6)
      );
      IEnumerable<XElement> list = root.XPathSelectElements("./Child2");
      foreach (XElement el in list)
          Console.WriteLine(el);
   }
}

   
    
    
    
  








Related examples in the same category

1.XPathNavigator
2.XPathNodeIterator
3.Select by path
4.Find Elements with an XPath SearchFind Elements with an XPath Search
5.XPath Query Demo
6.Read XML node using the XML path
7.XmlQuery Example
8. XPath Expression Syntax
9.Using XPath to get string value, integer value and boolean value
10.Extensions.XPathSelectElement selects an XElement using a XPath expression
11.Returns the string result from evaluating an xpath expression against the given document and context.
12.Gets the text value from the element located by the given XPath.
13.Returns the inner text of the single node selected from the specified xpath if found; otherwise, null.
14.Get an array of nodes matching an XPath expression
15.Schema Reference Util