I have xml structure like this:
<Group id="2" name="Third" parentid="0" />
<Group id="6" name="Five" parentid="4" />
<Group id="3" name="Four" parentid="2" />
<Group id="4" name="Six" parentid="1" />
parent is denotes Group’s Id.
The Constructor of Group reads like:
public Group(string name, int ID, Group parent)
While De-serializing, how do I get parent using Id and pass into group?
If you are using the inbuilt processing, then
XmlSerializeronly really wants to use the default constructor. You could do that via:but note that there is a big difference between a
Groupparent 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:You might translate that as:
this should do what you need.