Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xml schema question

From: Robert Koberg <rob@------.--->
To: George Cristian Bina <george@----.-->
Date: 7/22/2004 10:40:00 PM
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
> www.---.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
>>
>

From george@s...  Fri Jul 23 08:56:53 2004


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent