using System.Collections;
using System.Collections.Generic;
public static void Main()
XElement root = new XElement("Root",
new XAttribute("a", "bb"),
new XElement("Child", 0),
new XElement("Child", new XElement("Grandchild", new XElement("Child", 25))),
new XElement("Child", new XAttribute("Source", "abc"), 2),
new XElement("Child", 3),
new XElement("Child", 4, new XAttribute("x", "y")),
Console.WriteLine("1---");
var el = root.Element("Child");
Console.WriteLine("2---");
Console.WriteLine("3---");
Console.WriteLine(string.Join(", ", root.Elements("Child").Where(o => o.Attribute("Source") != null).Select(x => x.ToString())));
Console.WriteLine("4---");
var desc = root.Elements("Child").ToList();
desc.ForEach(x => Console.WriteLine(x));
Console.WriteLine("5---");
desc = root.Descendants("Child").ToList();
desc.ForEach(x => Console.WriteLine(x));