Schema: restrict occurences but not order

T

thierry

Hi,

I am trying to do something apparently simple but I cannot succeed.
I try to write a schema for an element containing several children
in any order but I want to restrict the number of occurrences of
each children.

This would be something like that, without the ordering which is
imposed by xs:sequence:

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="a" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="b" minOccurs="1" maxOccurs="unbounded" />
<xs:element name="c" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>

For instance, the following should pass:

<root> <b/> <c/> <b/> <a/> </root>

But the following should not (two many <c/>):

<root> <b/> <c/> <b/> <c/> </root>

I tried several combinations using xs:all or xs:choice but I either
fail to restrict the number of occurences or fail to allow any order.

Your help will be greatly appreciated.

<thierry/>
 
J

Joe Kesselman

Not possible in XML Schema unless you spell out all the possible
alternative sequences, which rapidly becomes hugely verbose for any but
the simplest cases. Generally folks don't try to implement this kind of
restriction in their schemas, but instead handle it in application
code and/or user documentation.

(SGML had a simple way to express this pattern. XML deliberately dropped
that because it's a Royal Pain to implement correctly, requiring some
nonstandard parser/grammar technology.)
 
T

thierry

Joe Kesselman wrote :
Not possible in XML Schema unless you spell out all the possible
alternative sequences, which rapidly becomes hugely verbose for any but
the simplest cases. Generally folks don't try to implement this kind of
restriction in their schemas, but instead handle it in application code
and/or user documentation.

Too bad... Thanks for your help. Will check the number of occurences in the
application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,818
Messages
2,569,727
Members
45,661
Latest member
NadineBour

Latest Threads

Top