Get the child nodes from XElement in CSharp

Description

The following code shows how to get the child nodes from XElement.

Example


     /* ww w.  j  av a2  s  . c  om*/

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

        Console.WriteLine(bench);
        foreach (XElement e in bench.Elements())
            Console.WriteLine(e.Name + "=" + e.Value);
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style