[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: enforce at least one element and at most N from a set of N

  • From: "Pete Cordell" <petexmldev@t...>
  • To: "dave" <ceek63@y...>, <xml-dev@l...>
  • Date: Mon, 5 Nov 2007 10:11:26 -0000

Re:  enforce at least one element and at most N from a set of N
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:  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
>
> 




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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.