I have a complex graph of XML-serializable classes that I’m able to (de)serialize to hard-disk just fine. But how do I handle massive changes to the graph schema structure? Is there some mechanism to handle XML schema upgrades? Some classes that would allow me to migrate old data to the new format?
Sure I could just use XmlReader/XmlWriter, go through every node and attribute and write several thousand lines of code to convert data to the new format, but maybe there is a better way?
I have found Object graph serialization in .NET and code version upgrades, but I don’t think the linked articles apply when there are major changes in the model.
Instead of writing several thousand lines of code to convert files using
XmlReader/XmlWriter, you could use XSLT. We are still talking hundreds of lines of code, and perhaps slower execution speeds, but if you are good at XSLT you could get it done much faster.The other approach would be to build a C# program that links both the old class and the new class (of course you’d need to rename the old class to avoid naming collision). The program would load
OldMyClassfrom disk, constructNewMyClassfrom the values of its attributes, and serializeNewMyClassto disk. Essentially, this approach moves the task of conversion into the C# territory, which may be a lot more familiar to you.