I would suggest you use different approach. If you need to persist some data, not matter what kind,
you don't have to work with XML directly.
You can use
Data Contract. This is the most non-intrusive way to add persistence to and arbitrary data type structure. You just add attributes
[DataContract]
and
[DataMember]
. When you have some data graph formed by the instances of you data classes participated in the contract (this graph does not even have to be a tree: circular references will be successfully resolved automatically), you can use
System.Runtime.Serialization.DataContractSerializer
to save and restore data to any stream.
Your XML schema will be created on the fly. With Data Contract, the part of contract is only what is marked with the attributes. You can change anything else and be not afraid of the risk of breaking the contract. It's also very easy to evolve your data schema incrementally as you develop new versions of your software: you just add new contract members/types. You won't need to create any kind of conversion from the data of old version to a new version.
See:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx[
^].
—SA