通过从完全相同的类型向后兼容扩展来修改现有的XSD类型吗? [英] Is modifying existing XSD type by extending it from exact same type backward compatible?

查看:54
本文介绍了通过从完全相同的类型向后兼容扩展来修改现有的XSD类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为由客户实现的WS制作了较早的XSD + WSDL.我们实施客户.我在WS Create-operation中有这样的类型:

I made earlier XSD+WSDL for a WS that is implemented by a customer. We implement the client. I have type like this in WS Create-operation:

<xs:complexType name="tWorkCreate">
 <xs:sequence>
  <xs:element ref="plan:workkey"  />
  <xs:element ref="plan:workdata"  />
 </xs:sequence>
</xs:complexType>

现在,我想对新的Update操作使用相同的类型,但是命名是错误的.所以我打算这样做:

Now I would like to use the same type for new Update-operation, but naming is wrong. So I plan to do like this:

<xs:complexType name="tWorkSet">
 <xs:sequence>
  <xs:element ref="plan:workkey"  />
  <xs:element ref="plan:workdata"  />
 </xs:sequence>
</xs:complexType>


<xs:complexType name="tWorkCreate">
 <xs:complexContent>
  <xs:extension base="tWorkSet">
    <xs:sequence>
    </xs:sequence>
  </xs:extension>
 </xs:complexContent>
</xs:complexType>

,并将 tWorkSet 直接用于 Update 操作( tWorkCreate 操作将是相同的).现有客户不需要(也没有实现) Update .不复制类型的原因是,例如,我们可以在代码中类似地处理 Update Create .因此,最好只是复制类型,还是这种扩展方案明智?

and use tWorkSet directly for Update operation (tWorkCreate operation would be the same). The existing customer does not need (and is not implementing) Update. The reason for not duplicating the type is e.g that we could handle both Update and Create similarly in code. So is it better just to duplicate the type or is this extension scenario sensible?

推荐答案

是的,以这种方式重构类型定义是一个好主意,并且向后兼容 1 .在类型重构之前有效的所有相同XML文档在重构之后都将有效.实际上,它比向后兼容要好,因为完全相同的XML文档在更改之前是有效的,而在更改之后才是有效的.

Yes, refactoring type definitions in this manner is a good idea and is backward compatible1. All of the same XML documents that were valid before the type refactoring will be valid after the refactoring. In fact, it's better than backward compatible because exactly the same set of XML documents that were valid before the change will be valid after the change.

1 假定客户端本身不直接依赖类型名称,例如通过XML文档实例中使用的JAXB绑定或 xsi:type .[感谢 Petru Gardea.]

1Assuming that clients have no direct dependencies against the type names themselves such as via JAXB bindings or xsi:type use in XML doc instances. [Thanks to Petru Gardea.]

这篇关于通过从完全相同的类型向后兼容扩展来修改现有的XSD类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆