XSD sequence shows as abiguous!

Posted by Tim C on Stack Overflow See other posts from Stack Overflow or by Tim C
Published on 2010-04-09T22:17:30Z Indexed on 2010/04/09 23:03 UTC
Read the original article Hit count: 366

Filed under:
|
|
|

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!

Edit: To be a bit more concise here are the possible outputs of the XML that would validate with this schema:

<list>
    <preamble>My Preamble</preamble>
    <title>My Title</title>
</list>

or:

<list>
    <title>My Title</title>
    <preamble>My Preamble</preamble>
</list>

As you can see it can be either one way or the other but not both. Also you could just have a title or a preamble and not both.

© Stack Overflow or respective owner

Related posts about xsd

Related posts about Xml