问题描述
我试图在不破坏此元素现有合同的情况下使用元素内的数据.
让我们简化一下我的案例:
I am trying to use data within an element without breaking this element existing contract.
Let's simplify my case:
<xs:element name="ExistingContract">
<xs:complexType>
<xs:sequence>
<xs:element name="first" type="FirstType"/>
<xs:element name="second" type="SecondType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewContract">
<xs:complexType>
<xs:sequence>
<xs:element name="first" type="FirstType"/>
<xs:element name="second" type="SecondType"/>
<xs:element name="additionalData" type="AdditionalDataType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
这两个内部类型是重复的,我想避免它.由于内部数据没有任何现有的包装 xs:complexType
,我可以从 ExistingContract
中取出它并在我的 NewContract
中使用它.但是我会打破第一份合同(我不想这样做).
These two inner types are duplicated, and I want to avoid it. Since there isn't any existing wrapping xs:complexType
for the inner data, I can take it out from ExistingContract
and use it in my NewContract
. But then I will break the first contract (which I don't want to).
您是否熟悉任何 XSD 方法,我可以保持第一个合约不变并将其内部数据提取到我的新合约中?
Are you familiar with any XSD method that I can keep the first contract the same and extract its inner data to my new contract?
推荐答案
您可以使用 xs:extension
从 ExistingContractType
扩展 NewContractType
:
You can use xs:extension
to extend NewContractType
from ExistingContractType
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ExistingContract" type="ExistingContractType"/>
<xs:complexType name="ExistingContractType">
<xs:sequence>
<xs:element name="first" type="FirstType"/>
<xs:element name="second" type="SecondType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="NewContractType">
<xs:complexContent>
<xs:extension base="ExistingContractType">
<xs:sequence>
<xs:element name="additionalData" type="AdditionalDataType"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="NewContract" type="NewContractType"/>
<xs:complexType name="FirstType"/>
<xs:complexType name="SecondType"/>
<xs:complexType name="AdditionalDataType"/>
</xs:schema>
这篇关于在 XSD 中扩展复杂类型的示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!