XSD sequence shows as ambiguous

对着背影说爱祢 提交于 2019-12-11 01:45:24

问题


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"/>
      </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!


回答1:


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?



来源:https://stackoverflow.com/questions/2611312/xsd-sequence-shows-as-ambiguous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!