You can do this in a variety of ways in C# but you probably want to implement
IXmlSerializable
on each object:
public interface IXmlSerializable
{
XmlSchema GetSchema ();
void ReadXml ( XmlReader reader );
void WriteXml ( XmlWriter writer );
}
...and cascade the process from root to bottom. Implementing the interface gives you a very fine grained way of controlling/debugging the process. You can either use:
-
XMLSerializer
or (this is the prefered and better tool)
-
DataContractSerializer
The code for this is too involved to post it here. But you should look for solutions that serialize tree or multi tree (graph) structures and you should find a few samples that give you a more detailed idea on this one.