If you are using the inbuilt processing, then XmlSerializer
only really wants to use the default constructor. You could do that via:
public class Group {
public Group() {}
[XmlAttribute("id")]
public int Id {get;set;}
[XmlAttribute("name")]
public string Name {get;set;}
[XmlAttribute("parentid")]
public int ParentId {get;set;}
}
but note that there is a big difference between a Group
parent and a parent-id. I suspect the best approach would be to either write the data in a more hierarchical fashion, or to stick with what you have, but use a simple DTO during deserialization. Then translate this data into what you actually want in the next stage. So, if you have:
List<GroupDTo> groups = ...
You might translate that as:
var actualGroups = from group in groups
select new Group(group.Id, group.Name,
groups.FirstOrDefault(x => x.Id == group.ParentId));
this should do what you need.