XElement.DescendantsAndSelf returns this element and all descendant elements : Descendants « XML LINQ « C# / C Sharp






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

1.Has elements and has attributes
2.Get parent element
3.Traversing Down from an XElement Object via the Descendants Method
4.Calling the First Descendants Prototype
5.Calling the Second Descendants Prototype
6.XElement.DescendantNodesAndSelf: this element, and all descendant nodes
7.XElement.DescendantsAndSelf returns this element, and all descendant elements of this element