XElement.DescendantNodesAndSelf: this element, and all descendant nodes
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<XNode> dnas = from node in xmlTree.DescendantNodesAndSelf()
select node;
foreach (XNode node in dnas)
{
if (node is XElement)
Console.WriteLine((node as XElement).Name);
else
Console.WriteLine(node);
}
}
}
Related examples in the same category