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 aas = from el in gc.AncestorsAndSelf()
select el;
foreach (XElement el in aas)
Console.WriteLine(el.Name);
}
}