The Elements method returns just the child nodes of type XElement
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
public class MainClass {
public static void Main() {
var bench = new XElement("bench",
new XElement("A",
new XElement("B", "H"),
new XElement("B", "R")
),
new XElement("A",
new XElement("B", "S"),
new XElement("C", "N")
),
new XComment("comment")
);
foreach (XElement e in bench.Elements())
Console.WriteLine(e.Name + "=" + e.Value);
}
}
Related examples in the same category