使用限制机制进行复杂类型派生
在 BizTalk 编辑器功能方面,通过限制进行派生与通过扩展进行派生类似。 通过限制派生的复杂类型与其基本数据类型类似,只是其声明比基本数据类型中的相应声明具有更多限制性。 实际上,新类型所表示的值是基本数据类型所表示的值的子集(与简单类型限制的情况一样)。 使用基本数据类型的值的应用程序应当能够成功处理所有限制的类型的值。
有关使用限制机制派生新的复杂类型的全面信息,请参阅 W3C 网站。 有关此网站和其他网站的各种链接,请参阅 Web 上的 XSD 资源。
若要通过限制从复杂的全局类型派生,请在架构树中的另一个位置,首先在所需位置插入新的 Record 节点。 然后将其 基数据类型 属性设置为复杂全局类型的名称。 最后,至少在将基数据类型设置为“限制”时,将 Derived By 属性的设置从其默认值“Extension) (”。
在以下示例中, BillingAddress 是新插入的 Record 节点的名称, GlobalAddrType 是它派生自的复杂全局类型的名称,并打算对其进行限制。 在架构树视图中,名为 BillingAddress 的节点下方会显示重复的节点结构,这与名为 ShippingAddress 的节点下的相邻节点结构相同。 它们之间的区别在于 BillingAddress 节点结构将受到基数据类型 GlobalAddrType 的可能限制, 而 ShippingAddress 结构将保持与基本数据类型 GlobalAddrType 相同。
由于已选择限制基本数据类型,因此您不能插入任何新节点,但可以更改现有节点的属性,以便进一步限制其可能值或行为。
以前, 派生者 属性仍设置为 Extension。
<xs:schema> <xs:element name="Root"> <xs:complexType> <xs:sequence> <xs:element name="ShippingAddress" type="GlobalAddrType" /> <xs:element name="BillingAddress"> <xs:complexType> <xs:complexContent mixed="false"> <xs:extension base="GlobalAddrType" /> </xs:complexContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="GlobalAddrType"> [Address structure defined globally here.] </xs:complexType> </xs:schema>
在将 Derived By 属性从 Extension 切换为 “限制”后。
<xs:schema> <xs:element name="Root"> <xs:complexType> <xs:sequence> <xs:element name="ShippingAddress" type="GlobalAddrType" /> <xs:element name="BillingAddress"> <xs:complexType> <xs:complexContent mixed="false"> <xs:restriction base="GlobalAddrType"> [Duplicate of address structure now appears here, ready to be restricted with additional attributes, set using the properties of the relevant nodes in the schema tree.] </xs:restriction> </xs:complexContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="GlobalAddrType"> [Address structure defined globally here.] </xs:complexType> </xs:schema>