Skip to content

How to Upgrade from v1.x to v2

Mike-EEE edited this page Nov 29, 2019 · 2 revisions

Finally, if you have documents from v1, you will need to upgrade them to v2 to work. This involves reading the document in an instance of v1 serializer, and then writing it in an instance of v2 serializer. We have provided the ExtendedXmlSerializer.Legacy nuget package to assist in this goal.

    <?xml version="1.0" encoding="utf-8"?>
    <ArrayOfSubject>
        <Subject type="ExtendedXmlSerializer.Samples.Introduction.Subject">
            <Message>First</Message>
            <Count>0</Count>
        </Subject>
        <Subject type="ExtendedXmlSerializer.Samples.Introduction.Subject">
            <Message>Second</Message>
            <Count>0</Count>
        </Subject>
        <Subject type="ExtendedXmlSerializer.Samples.Introduction.Subject">
            <Message>Third</Message>
            <Count>0</Count>
        </Subject>
    </ArrayOfSubject>
    ExtendedXmlSerialization.ExtendedXmlSerializer legacySerializer = new ExtendedXmlSerialization.ExtendedXmlSerializer();
    string content = File.ReadAllText(@"bin\Upgrade.Example.v1.xml"); // Path to your legacy xml file.
    List<Subject> subject = legacySerializer.Deserialize<List<Subject>>(content);
    
    // Upgrade:
    IExtendedXmlSerializer serializer = new ConfigurationContainer().Create();
    string contents = serializer.Serialize(new XmlWriterSettings {Indent = true}, subject);
    File.WriteAllText(@"bin\Upgrade.Example.v2.xml", contents);
    // ...
    <?xml version="1.0" encoding="utf-8"?>
    <List xmlns:ns1="clr-namespace:ExtendedXmlSerializer.Samples.Introduction;assembly=ExtendedXmlSerializer.Samples" xmlns:exs="https://extendedxmlserializer.github.io/v2" exs:arguments="ns1:Subject" xmlns="https://extendedxmlserializer.github.io/system">
      <Capacity>4</Capacity>
      <ns1:Subject>
        <Message>First</Message>
        <Count>0</Count>
      </ns1:Subject>
      <ns1:Subject>
        <Message>Second</Message>
        <Count>0</Count>
      </ns1:Subject>
      <ns1:Subject>
        <Message>Third</Message>
        <Count>0</Count>
      </ns1:Subject>
    </List>