XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] enforce at least one element and at most N from a set of N elements- XSD how?

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@yahoo.com>
To: <xml-dev@lists.xml.org>
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@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
> 




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS