I have an XML like this:
And I have a Member class with property Name.
How can I read every Unit and its children Units into multiple generic List
class Unit
{
public string Name;
public List Children;
public Unit(string name, List children)
{
Name = name;
Children = children;
}
public static Unit Convert(XElement elem)
{
return new Unit(elem.Attribute("Name").Value, Convert(elem.Elements()));
}
public static List Convert(IEnumerable elems)
{
return elems.Select(Unit.Convert).ToList();
}
}
You can use it like this:
Unit.Convert(XDocument.Parse(xml).Root.Elements())