XSD 遵循一种或另一种元素格式

XSD follow one element format or another

我必须验证可以遵循两种给定格式的复杂类型。 <section> 必须出现两次。 <section> 可以两次都遵循第一种格式,两次都遵循第二种格式,或者 format1 和 format2 的组合各一次。

<!--FORMAT 1-->
<section>
    <!-- <section> can follow one of two formats -->
    <!-- Elements will appear in sequence-->
    <title>I'm a title</title>
    <authors>
        <author>Helen Sharp</author>
        <author>Yvonne Rogers</author>
        <author>Jenny Preece</author>
    </authors>
    <publisher year="2019">Wiley</publisher>
</section>

<!--FORMAT 2-->
<section>
    <!-- Elements will appear in sequence-->
    <isbn>
        <isbn>1119547253</isbn>
        <isbn>9781119547259</isbn>
    </isbn>
    <notes> I'm a note </notes>
    <format>Print book</format>
    <edition>5</edition>
    <subjects>
        <subject>Hello</subject>
    </subjects>
</section>

我想也许我可以在其中使用 <xs:choice>,然后使用 <xs:sequence>,但我收到以下错误:Element 'choice' Is Invalid, Misplaced, Or Occurs Too Often.

到目前为止我的代码如下所示:

<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="section" minOccurs="2" maxOccurs="2">
                <xs:complexType>
                    <xs:choice> <!--This choice will be for format 1-->
                        <xs:sequence>
                            <!--other validation for format1-->
                        </xs:sequence>
                    </xs:choice>
                    
                    <xs:choice> <!--This choice will be for format 2-->
                        <xs:sequence>
                            <!--other validation for format2-->
                        </xs:sequence>
                    </xs:choice>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

我能理解为什么这行不通,但这是我唯一能想到的。也许我缺少什么?任何帮助都会非常棒:)

替换

            <xs:choice> 
                <xs:sequence>
                    <!--other validation for format1-->
                </xs:sequence>
            </xs:choice>
            
            <xs:choice> 
                <xs:sequence>
                    <!--other validation for format2-->
                </xs:sequence>
            </xs:choice>

来自

            <xs:choice>
                <xs:sequence>
                    <!--other validation for format1-->
                </xs:sequence>
                <xs:sequence>
                    <!--other validation for format2-->
                </xs:sequence>
            </xs:choice>