0

I have a XSD file in which I have the following situation:

<xs:element name='test'>
  <xs:complexType>
   <xs:all>
    <xs:element ref='el1' minOccurs='0' maxOccurs='1'/>
    <xs:element ref='el2' minOccurs='0' maxOccurs='1'/>
    <xs:element ref='el3' minOccurs='0' maxOccurs='1'/>
    <xs:element ref='el4' minOccurs='0' maxOccurs='1'/>
    <xs:element ref='el5' minOccurs='0' maxOccurs='1'/>
    <xs:element ref='el6' minOccurs='0' maxOccurs='1'/>
    <xs:element ref='el7' minOccurs='0' maxOccurs='1'/>    
    <xs:element ref='el8' minOccurs='0' maxOccurs='unbounded'/>  
   </xs:all>
   <xs:attribute name='attr1' use='optional' type='yesno'/>
  </xs:complexType>
 </xs:element>

And now the problem is, this isn't working so far, cause I can't have maxOccurs='unbounded' within the all element. Is there any way to achieve this, e.g. with using xs:choice?

marc3l
  • 2,525
  • 7
  • 34
  • 62

1 Answers1

2

To preserve the cardinality you want, the only way in XSD 1.0 is to wrap your repeating element with another one, like so:

<xs:element name='test'>
    <xs:complexType>
        <xs:all>
            <xs:element ref='el1' minOccurs='0'/>
            <xs:element ref='el2' minOccurs='0'/>
            <xs:element ref='el3' minOccurs='0'/>
            <xs:element ref='el4' minOccurs='0'/>
            <xs:element ref='el5' minOccurs='0'/>
            <xs:element ref='el6' minOccurs='0'/>
            <xs:element ref='el7' minOccurs='0'/>
            <xs:element ref='el8w' minOccurs='0'/>
        </xs:all>
        <xs:attribute name='attr1' type='yesno'/>
    </xs:complexType>
</xs:element>
<xs:element name="el8w">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="el8" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

The (repeating) choice that would mimic the xs:all (i.e. allow for interspersed elements with the indicated cardinality) can't enforce the occurrence of individual particles.

Petru Gardea
  • 21,373
  • 2
  • 50
  • 62
  • Can I have ? You have written . maxOccurs is missing?! – marc3l Sep 11 '13 at 13:56
  • The default value of maxOccurs is one. I am used to (and my tooling does it, too) remove superfluous attributes. The same goes for `use` in schema attributes, the default is optional. – Petru Gardea Sep 11 '13 at 15:06