Question

I'm trying to represent the following DTD fragment in XSD:-

(A | B)* | (A | C)* | (A | D)* | ...

i.e. a mixed list of any number of As and any number of one of B, C, D, ...

CastorConverter spits out:-

              <choice>
                    <choice minOccurs="0" maxOccurs="unbounded">
                          <element ref="tns:A" />
                          <element ref="tns:B" />
                    </choice>
                    <choice minOccurs="0" maxOccurs="unbounded">
                          <element ref="tns:A" />
                          <element ref="tns:C" />
                    </choice>
                    <choice minOccurs="0" maxOccurs="unbounded">
                          <element ref="tns:A" />
                          <element ref="tns:D" />
                    </choice>
              </choice>

but this gives me a parser error. Investigating with visual studio brings up the following warning:-

"Multiple definition of element 'A' 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."

The problem appears to be that if the parser encounters an "A" will need to "look-ahead" to the rest of the sequence in order to determine which choice to validate against.

Is there another way I can represent this sequence in XSD?

Was it helpful?

Solution

Use sequences, like this:

<sequence minOccurs="0">
  <element minOccurs="0" maxOccurs="unbounded" ref="tns:A" />
  <choice>
    <sequence>
      <element minOccurs="1" maxOccurs="unbounded" ref="tns:B" />
      <sequence minOccurs="0" maxOccurs="unbounded">
        <element maxOccurs="unbounded" ref="tns:A" />
        <element minOccurs="0" maxOccurs="unbounded" ref="tns:B" />
      </sequence>
    </sequence>
    <sequence>
      <element minOccurs="1" maxOccurs="unbounded" ref="tns:C" />
      <sequence minOccurs="0" maxOccurs="unbounded">
        <element maxOccurs="unbounded" ref="tns:A" />
        <element minOccurs="0" maxOccurs="unbounded" ref="tns:C" />
      </sequence>
    </sequence>
    <sequence>
      <element minOccurs="1" maxOccurs="unbounded" ref="tns:D" />
      <sequence minOccurs="0" maxOccurs="unbounded">
        <element maxOccurs="unbounded" ref="tns:A" />
        <element minOccurs="0" maxOccurs="unbounded" ref="tns:D" />
      </sequence>
    </sequence>
  </choice>
</sequence>

alt text http://www.freeimagehosting.net/uploads/29c07bafa2.png

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top