XElement.DescendantNodesAndSelf: this element, and all descendant nodes : Descendants « XML LINQ « C# / C Sharp






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

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.DescendantsAndSelf returns this element and all descendant elements
7.XElement.DescendantsAndSelf returns this element, and all descendant elements of this element