Re: xml schema question

Just curious: Could something like this work?


<xsd:element name='element'>
 <xsd:complexType>
     <xsd:choice minOccurs='0' maxOccurs='unbounded'>
          <xsd:element ref='dd'/>
          <xsd:element ref='cc'/>
          <xsd:element ref='aa' minOccurs='1' maxOccurs="1"/>
          <xsd:element ref='bb' minOccurs='1' maxOccurs="1"/>
      </xsd:choice>
  </xsd:complexType>
</xsd:element>

In other words, can you override the choice's min/max at the element level?

best,
-Rob


George Cristian Bina wrote:

>
> Hi Peter,
>
> The following schema will do it.
> The model is:
> (
>  (aa, ((bb, (cc | dd)*) | ((cc | dd)+, bb, (cc | dd)*))) |
>  (bb, ((aa, (cc | dd)*) | ((cc | dd)+, aa, (cc | dd)*))) |
>  (
>   (cc | dd)+,
>   (
>    (aa, ((bb, (cc | dd)*) | ((cc | dd)+, bb, (cc | dd)*))) |
>    (bb, ((aa, (cc | dd)*) | ((cc | dd)+, aa, (cc | dd)*)))
>   )
>  )
> )
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>     <xsd:element name="element">
>         <xsd:complexType>
>             <xsd:choice>
>                 <xsd:sequence>
>                     <xsd:element ref="aa"/>
>                         <xsd:choice>
>                             <xsd:sequence>
>                                 <xsd:element ref="bb"/>
>                                 <xsd:choice minOccurs="0" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                             </xsd:sequence>
>                             <xsd:sequence>
>                                 <xsd:choice minOccurs="1" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                                 <xsd:element ref="bb"/>
>                                 <xsd:choice minOccurs="0" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                             </xsd:sequence>
>                         </xsd:choice>
>                 </xsd:sequence>
>                 <xsd:sequence>
>                     <xsd:element ref="bb"/>
>                     <xsd:choice>
>                         <xsd:sequence>
>                             <xsd:element ref="aa"/>
>                             <xsd:choice minOccurs="0" 
> maxOccurs="unbounded">
>                                 <xsd:element ref="cc"/>
>                                 <xsd:element ref="dd"/>
>                             </xsd:choice>
>                         </xsd:sequence>
>                         <xsd:sequence>
>                             <xsd:choice minOccurs="1" 
> maxOccurs="unbounded">
>                                 <xsd:element ref="cc"/>
>                                 <xsd:element ref="dd"/>
>                             </xsd:choice>
>                             <xsd:element ref="aa"/>
>                             <xsd:choice minOccurs="0" 
> maxOccurs="unbounded">
>                                 <xsd:element ref="cc"/>
>                                 <xsd:element ref="dd"/>
>                             </xsd:choice>
>                         </xsd:sequence>
>                     </xsd:choice>
>                 </xsd:sequence>
>                 <xsd:sequence>
>                     <xsd:choice minOccurs="1" maxOccurs="unbounded">
>                         <xsd:element ref="cc"/>
>                         <xsd:element ref="dd"/>
>                     </xsd:choice>
>                     <xsd:choice>
>                         <xsd:sequence>
>                             <xsd:element ref="aa"/>
>                             <xsd:choice>
>                             <xsd:sequence>
>                                 <xsd:element ref="bb"/>
>                                 <xsd:choice minOccurs="0" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                             </xsd:sequence>
>                             <xsd:sequence>
>                                 <xsd:choice minOccurs="1" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                                 <xsd:element ref="bb"/>
>                                 <xsd:choice minOccurs="0" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                             </xsd:sequence>
>                         </xsd:choice>
>                         </xsd:sequence>
>                         <xsd:sequence>
>                             <xsd:element ref="bb"/>
>                             <xsd:choice>
>                             <xsd:sequence>
>                                 <xsd:element ref="aa"/>
>                                 <xsd:choice minOccurs="0" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                             </xsd:sequence>
>                             <xsd:sequence>
>                                 <xsd:choice minOccurs="1" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                                 <xsd:element ref="aa"/>
>                                 <xsd:choice minOccurs="0" 
> maxOccurs="unbounded">
>                                     <xsd:element ref="cc"/>
>                                     <xsd:element ref="dd"/>
>                                 </xsd:choice>
>                             </xsd:sequence>
>                         </xsd:choice>
>                         </xsd:sequence>
>                     </xsd:choice>
>                 </xsd:sequence>
>             </xsd:choice>
>         </xsd:complexType>
>     </xsd:element>
>     <xsd:element name="aa"/>
>     <xsd:element name="bb"/>
>     <xsd:element name="cc"/>
>     <xsd:element name="dd"/>
> </xsd:schema>
>
>
> Hope that helps,
> George
> -----------------------------------------------
> George Cristian Bina
> <oXygen/> XML Editor & XSLT Editor/Debugger
> http://www.oxygenxml.com
>
>
> Peter Menzel wrote:
>
>>
>> Hi all,
>>
>> i am working on a xml schema and have the following problem, maybe 
>> somebody can help me.
>>
>> I would like to have the follwoing element with content:
>>
>> <element>
>>   <aa/>
>>   <cc/>
>>   <bb/>
>> </element>
>>
>> The elements aa and bb are required to be there and they have to 
>> occur exactly once.
>> Other sub elements of element can occur many times. Especially the 
>> order of the elements is random, so i may not use xsd:sequence.
>>
>> My xml schema snippet for this element:
>>
>> <xsd:element name='element'>
>>  <xsd:complexType>
>>      <xsd:choice>
>>           <xsd:element ref='dd' minOccurs='0' maxOccurs='unbounded'/>
>>           <xsd:element ref='cc' minOccurs='0' maxOccurs='unbounded'/>
>>           <xsd:element ref='aa' minOccurs='1' maxOccurs="1"/>
>>           <xsd:element ref='bb' minOccurs='1' maxOccurs="1"/>
>>       </xsd:choice>
>>   </xsd:complexType>
>> </xsd:element>
>>
>> Unfortunately this wont work.
>> xmllint says that the above xml document is not valid with this schema.
>>
>> Has anybody any idea concerning this problem? Is it generally 
>> possible to mix elements in a complexType  with different 
>> minOccurs/maxOccurs ?
>>
>> Greetings, Peter
>>
>

Received on Friday, 23 July 2004 08:42:23 UTC