在 complexType 中添加一个新选择,其中的选择来自第二个 XSD importing/including 主要 XSD
Adding a new choice in a complexType with choices from a second XSD importing/including the main XSD
我有一个 XSD,其中我有一个 complexType 定义了一些选项,例如...
<xs:complexType name="ABC">
<xs:sequence>
<xs:choice>
<xs:element minOccurs="0" name="a" type="xs:string" />
<xs:element minOccurs="0" name="b" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
现在,如果我想为 complexType ABC 的现有序列添加更多选择,但是通过另一个 XSD 文件,因为我不想更改第一个文件以进行自定义更改。可以这样做吗?
您可以尝试以下方法:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:include schemaLocation="abc.xsd"/>
<xs:complexType name="abcde">
<xs:complexContent>
<xs:extension base="ABC">
<xs:choice>
<xs:element name="c"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
我有一个 XSD,其中我有一个 complexType 定义了一些选项,例如...
<xs:complexType name="ABC">
<xs:sequence>
<xs:choice>
<xs:element minOccurs="0" name="a" type="xs:string" />
<xs:element minOccurs="0" name="b" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
现在,如果我想为 complexType ABC 的现有序列添加更多选择,但是通过另一个 XSD 文件,因为我不想更改第一个文件以进行自定义更改。可以这样做吗?
您可以尝试以下方法:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:include schemaLocation="abc.xsd"/>
<xs:complexType name="abcde">
<xs:complexContent>
<xs:extension base="ABC">
<xs:choice>
<xs:element name="c"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>