Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] enforce at least one element and at most N from a set of N elements- XSD how?

From: "Pete Cordell" <petexmldev@--------------.--->
To: "dave" <ceek63@-----.--->, <xml-dev@-----.---.--->
Date: 11/5/2007 10:12:00 AM
If you can have the same element multiple times, then you can do:

    <xs:complexType name='..'>
        <xs:choice maxOccurs='4'>
            <xs:element name='element1'../>
            ...
        </xs:choice>
    <xs:complexType>

If each element can only appear once, then it is more problematic.  You can 
write a schema that spells out all the possible combinations, e.g.

    <xs:complexType name='..'>
        <xs:choice>
            <xs:sequence>
                <xs:element name='element1'../>
                <xs:element name='element2' minOccurs='0'.../>
                <xs:element name='element3' minOccurs='0'../>
                <xs:element name='element4' minOccurs='0'../>
            </xs:sequence>
            <xs:sequence>
                <xs:element name='element2'.../>
                <xs:element name='element3' minOccurs='0'../>
                <xs:element name='element4' minOccurs='0'../>
            </xs:sequence>
            <xs:sequence>
                <xs:element name='element3'../>
                <xs:element name='element4' minOccurs='0'../>
            </xs:sequence>
            <xs:sequence>
                <xs:element name='element4' minOccurs='0'../>
            </xs:sequence>
        </xs:choice>
    <xs:complexType>

But that's not particularly pretty and doesn't scale very well.  In that 
case it's often best to define a looser schema, and then impose the 
constraint at the application level.  An example schema for that might be:

    <xs:complexType name='..'>
            <xs:sequence>
                <xs:element name='element1' minOccurs='0'../>
                <xs:element name='element2' minOccurs='0'.../>
                <xs:element name='element3' minOccurs='0'../>
                <xs:element name='element4' minOccurs='0'../>
            </xs:sequence>
    <xs:complexType>

HTH,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/
for XML Schema to C++ data binding

----- Original Message ----- 
From: "dave" <ceek63@y...>
To: <xml-dev@l...>
Sent: Monday, November 05, 2007 4:02 AM
Subject: [xml-dev] enforce at least one element and at most N from a set of 
N elements- XSD how?


>
> How would I design an XSD to enforce-
>  at least one element and at most 4 elements must be
> present from a set of 4 elements.
>
> sequence/choice/all with minoccurs/maxoccurs doesn't
> seem to help here.
>
> Thanks
> -D
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@l...
> subscribe: xml-dev-subscribe@l...
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
>


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