@Dave正在爲ChildB添加一些愚蠢的屬性好嗎?由於您對childB的要求是0-1,我們可以通過向childB添加一個固定屬性並對屬性強制實施唯一約束來實現所需的解決方案。
<complexType name="childAType">
<simpleContent>
<extension base="string"></extension>
</simpleContent>
</complexType>
<complexType name="childBType">
<simpleContent>
<extension base="string">
<attribute name="value" type="string" fixed="123"></attribute>
</extension>
</simpleContent>
</complexType>
<element name="root">
<complexType>
<choice minOccurs="0" maxOccurs="unbounded">
<element name="childA" type="tns:childAType" minOccurs="0" maxOccurs="unbounded"></element>
<element name="childB" type="tns:childBType" minOccurs="0" maxOccurs="unbounded"></element>
</choice>
</complexType>
<unique name="childB.max.once">
<selector xpath="./tns:childB"></selector>
<field xpath="@value"></field>
</unique>
</element>
下面是有效的XML(B的順序無關緊要或B可以被排除)
<tns:root xmlns:tns=" ">
<tns:childA></tns:childA>
<tns:childB></tns:childB>
<tns:childA></tns:childA>
<tns:childA></tns:childA>
</tns:root>
之一。然而下面的一個是無效
<tns:root xmlns:tns=" ">
<tns:childB></tns:childB>
<tns:childA></tns:childA>
<tns:childB></tns:childB>
<tns:childA></tns:childA>
<tns:childA></tns:childA>
</tns:root>
Jasso。很多道歉,我應該爲此感謝你。我不得不繼續執行更高優先級的任務。我仍然沒有機會正確看待它,但我會按照答案打勾,因爲已經決定我們並不太擔心訂單限制,所以我可能永遠沒有機會真正地去掌握它。抱歉。 – Dave