Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApp10
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
XElement hier = doc.Descendants("n-hierarchy").FirstOrDefault();
Node root = new Node();
root.name = "root";
root.parse(hier);
}
}
public class Node
{
public string name { get; set; }
public string id { get; set; }
public List<Node> children { get;set;}
public void parse(XElement element)
{
foreach (XElement childElement in element.Elements("n"))
{
if (children == null) children = new List<Node>();
Node child = new Node();
children.Add(child);
child.name = (string)childElement.Attribute("name");
child.id = (string)childElement.Attribute("n_id");
child.parse(childElement);
}
}
}
}