The Elements method returns just the child nodes of type XElement

image_pdfimage_print
   
 

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);
    }
}

    


This entry was posted in XML LINQ. Bookmark the permalink.