XElement.DescendantsAndSelf returns this element, and all descendant elements of this element
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 XAttribute("Att1", "AttributeContent"),
new XElement("Child",
new XText("Some text"),
new XElement("GrandChild", "element content")
)
);
IEnumerable<XElement> das = xmlTree.DescendantsAndSelf("Child");
foreach (XElement el in das)
Console.WriteLine(el.Name);
}
}
Related examples in the same category