I got an email a little while ago from someone who read about my preferred XSD versioning strategy. They felt I had glossed over the issue of introducing a change that effects semantics and might be ignored by a receiver. Consider this example:
<element name=”Deposit”>
<complexType>
<sequence>
<element name=“Account“ type=“tn:AccountIdType“ />
<element name=“Amount“ type=“double“ minOccurs=“0“ />
</sequence>
</complexType>
</element>
Now suppose I evolved the schema by adding this optional element:
<element name=”Deposit”>
<complexType>
<sequence>
<element name=“Account“ type=“tn:AccountId“ />
<element name=“Amount“ type=“double“ minOccurs=“0“ />
<element name=“Currency“ type=“tn:CurrencyType“ minOccurs=“0“ />
</sequence>
</complexType>
</element>
The new Currency element is optional so that client who don't send it still work. They use the default currency that was used with the original version of the Deposit message. This works fine as long as you only never have new clients talking to old services. In that case, the client could send a Deposit with a Currency, but the old service would skip that unknown element (as per the rules I described in my original post).
The solution to this problem is to determine whether you will ever have the new client / old service situation (if you're services are deployed as single instance or always updated at the same time before any clients are released, then you never will). If you do, then exercise your judgement about changes. If you are going to change an XSD in a way that alters semantics, make sure you differentiate new instances somehow. For instance, you could add this to your schema:
<element name=”DepositWithCurrency”>
<complexType>
<sequence>
<element name=“Account“ type=“tn:AccountId“ />
<element name=“Amount“ type=“double“ minOccurs=“0“ />
<element name=“Currency“ type=“tn:CurrencyType“ minOccurs=“0“ />
</sequence>
</complexType>
</element>
This way you are versioning your schema, but not the Deposit element. This avoids the problem without introducing too much extra complexity.
Posted
May 05 2006, 02:27 PM
by
tim-ewald