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