XmlSerializer equivalent of IExtensibleDataObject

Posted by demoncodemonkey on Stack Overflow See other posts from Stack Overflow or by demoncodemonkey
Published on 2010-03-24T20:51:25Z Indexed on 2010/03/24 20:53 UTC
Read the original article Hit count: 455

With DataContracts you can derive from IExtensibleDataObject to allow round-tripping to work without losing any unknown additional data from your XML file.

I can't use DataContract because I need to control the formatting of the output XML. But I also need to be able to read a future version of the XML file in the old version of the app, without losing any of the data from the XML file.

e.g.

XML v1:

<Person>
    <Name>Fred</Name>
</Person>

XML v2:

<Person>
    <Name>Fred</Name>
    <Age>42</Age>
</Person>

If reading an XML v2 file from v1 of my app, deserializing and serializing it again turns it into an XML v1 file. i.e. the "Age" field is erased.

Is there anything similar to IExtensibleDataObject that I can use with XmlSerializer to avoid the Age field disappearing?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about serialization