XElement.AncestorsAndSelf returns a collection of elements : Ancestors « XML LINQ « C# / C Sharp






XElement.AncestorsAndSelf returns a collection of elements

 

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;


public class MainClass{
   public static void Main(){
        XElement xmlTree = new XElement("Root",
            new XElement("Child",
                new XElement("GrandChild", "element content")
            )
        );
        XElement gc = xmlTree.Element("Child").Element("GrandChild");
        IEnumerable<XElement> aas = from el in gc.AncestorsAndSelf()
                                    select el;
        foreach (XElement el in aas)
            Console.WriteLine(el.Name);
    }
}

   
  








Related examples in the same category

1.An Example of Calling the First Ancestors Prototype
2.Without Calling the Ancestors Operator
3.A More Concise Example of Calling the First Ancestors Prototype
4.Calling the Second Ancestors Prototype
5.XElement.AncestorsAndSelf(XName) returns a filtered collection of elements that contain this element