Returns a collection of the ancestor elements of this node.
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class MainClass{
public static void Main(){
XElement xmlTree = new XElement("Root",
new XElement("A",
new XElement("GrandChild", "content")
)
);
IEnumerable<XElement> grandChild = xmlTree.Descendants("GrandChild");
foreach (XElement el in grandChild.Ancestors())
Console.WriteLine(el.Name);
}
}
Related examples in the same category