tags:

views:

354

answers:

1

Hi,

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?

+2  A: 
Lucero
Hi, thanks so much for your answer.The sequence "A" should pass. Is it ok to add minOccurs="0" to the first-level nested sequences:-<sequence minOccurs="0"> <element minOccurs="0" maxOccurs="unbounded" ref="tns:A" /> <choice> <sequence minOccurs="0"> <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> ... </choice></sequence>That looks ok, you see any problems?
Iain Galloway
No (if I understood correctly), in that case, I would rather make <choice minOccurs="0"> instead, so that you allow any number of single A's but none of the B/C/D elements.
Lucero
Thanks again, you've really helped me out here!
Iain Galloway
You're welcome!
Lucero