XSD sequence shows as ambiguous
I have an XSD which was transformed from a RELAX NG schema with a few errors I am trying to fix. The big issue I have it with the following
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:sequence>
<xs:element minOccurs="0" ref="preamble"/>
<xs:element minOccurs="0" ref="title"/>
</xs:sequence>
<xs:sequence>
<xs:element minOccurs="0" ref="title"/>
<xs:element minOccurs="0" ref="preamble"/>
</xs:sequence>
</xs:choice>
<xs:group maxOccurs="unbounded" ref="block-selectionListItem"开发者_StackOverflow中文版/>
</xs:sequence>
<xs:attributeGroup ref="attlist-selectionList"/>
</xs:complexType>
</xs:element>
As you can see the xs:choice block allows you to pick between two xs:sequence blocks. Seems to make sense except that Visual Studio gives the following warning on the second <xs:element minOccurs="0" ref="title/>
element which is throwing everything off:
Multiple definition of element 'title' causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence.
Because you can only choose one I do not see how this is ambiguous. Any help would be greatly appreciated!
Answer:
As was pointed out in the answer below I was not accounting for all possibilities. So here is what I had to do:
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:group minOccurs ="0" maxOccurs="1" ref ="list-titlePreambleChoice"/>
<xs:group maxOccurs="unbounded" ref="block-basicListItem"/>
</xs:sequence>
<xs:attributeGroup ref="attlist-basicList"/>
</xs:complexType>
</xs:element>
This solved all my issues. Thanks!
It's ambiguous because of the minOccurs="0"
. If the validator finds a preamble
element, is it the first element of the first choice, or is it the second element of the second choice and the title
element is missing?
精彩评论