XSD2个元素一次,1个元素1+任意顺序

XSD 2 elements once, 1 element 1+ any order

我正在研究一个 XML 架构,其中包含 3 个元素,这些元素可以任何顺序

在下面的示例中,每个生物都有一个 favoriteColor 和一个 favoriteNumber,并且至少有一个 comment。我希望允许它们以任何顺序(包括交替)。

<xs:element name="bio">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="favoriteColor" maxOccurs="1" minOccurs="1"/>
            <xs:element name="favoriteNumber" maxOccurs="1" minOccurs="1"/>
            <xs:element name="comment" maxOccurs="unbounded" minOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

曾经有可能的选项是<xs:choice>,但它只允许其中一个选项。将每个可能的订单组合列为备用序列似乎很笨拙:(abc、acb、bac、bca、cab、cba)...而且它仍然没有考虑在其他两个之间散布评论的可能性。 (例如 "comment, number, comment, color, comment, comment" 应该被允许)

<xs:all> 会工作得很好,除了它只允许每个最多 1 个实例。我需要允许多个 "comment"。我可以将 <xs:element name="comment" maxOccurs="unbounded" minOccurs="0"/> 放在 "all" 标签的上方和下方,但这不起作用。见下文:

<xs:element name="bio">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="comment" maxOccurs="unbounded" minOccurs="0"/>
            <xs:all> <!-- not allowed here -->
                <xs:element ref="favoriteColor" maxOccurs="1" minOccurs="1"/>
                <xs:element ref="favoriteNumber" maxOccurs="1" minOccurs="1"/>
                <xs:element ref="comment" maxOccurs="1" minOccurs="1"/>
            </xs:all>
            <xs:element ref="comment" maxOccurs="unbounded" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

有什么建议吗?这个板上有很多问题与模式中元素的顺序有关,但我找不到任何解决我正在尝试做的事情的问题(我有 "only once" 和 "at least once)."

我认为不可能。甚至

<xs:sequence>
     <xs:element ref="comment" maxOccurs="unbounded" minOccurs="0" /> 
     <xs:element ref="comment" maxOccurs="unbounded" minOccurs="0" />
</xs:sequence> 

会给你报错。 (cos-nonambig:"test":comment 和 "test":comment(或其替换组中的元素)违反 "Unique Particle Attribution"。在针对此模式进行验证期间,将为这两个粒子创建歧义。 )