Schema: restrict occurences but not order

Thierry

Usenet Archive
Joined
Jun 2, 2000
Messages
31
Reaction score
0
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/>
 

Joe Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
1,229
Reaction score
0
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.)
 

Thierry

Usenet Archive
Joined
Jun 2, 2000
Messages
31
Reaction score
0
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
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top