Reputation: 4264
We have an application which uses xml serialization for serializing and deserializing its configuration settings.
We are going to release a new version of this application which has some drastic changes in its object model. Our users are not ready to reconfigure the settings with newer version. We need a solution that transforms the xml of previous version to newer version compatible xml. The newer version has some classes removed, renamed, properties added etc.
What is the best way to transform the older xml so that it can be deserialized by the newer version?
Upvotes: 1
Views: 348
Reputation: 2566
I think you would probably use MEF or SystemAddIns for versioing and extensibility of your OM, alongside with simple XML-to-Object mapper, like one i have invented http://xmlserialization.codeplex.com/
Upvotes: 0
Reputation: 35146
Keep two object graphs, one that represents old version and one that represents new version. Deserialize the old version and create the new object graph with it; so when the xml is saved next time; it will be saved using new schema. In the next release you can remove this backwards compatibility feature.
You can search the xml for patterns of old format and convert it to new xml using XSLT or code as suggested by Anders Abel. But this should be done automatically on load time. On saving the file you should warn the user that it will be saved using new format and will not be compatible with earlier versions.
Upvotes: 1
Reputation: 69280
When you first load the xml, you have to identify what version it is. The easiest is probably to make a function that transforms the old config into the new format. Then the new format loader can be used all the time and you can get rid of the old one and the old object model.
The transformation could be done either using xslt or with c# code.
Upvotes: 3