trouble getting correct schema

C

cmay

I am beginning to wonder if it is not possible to get this working.

I am trying to do:

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

With the following conditions:
1) a,b,c can be in any order
2) a and b can only be used 1 time
3) c can be used 0 to unbounded times.

Trying to do this with sequence, choice, all, each seem to miss one
part of the requirements.

Is this not possible?
 
G

George Bina

It is possible:

c*, (a, c*, b)|(b, c*, a), c*


<xs:element name="a"/>
<xs:element name="b"/>
<xs:element name="c"/>

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

Best Regards,
George
 
C

cmay

George,

Thanks for the reply and suggestion.

It looks like you are creating optional lists that depict the different
orders that could appear.

So while this might be doable for a,b,c the list would quickly grow out
of control if it were to expand from 3 possible elements to 10 or more.

Is that right?


Chris
 
J

Joe Kesselman

cmay said:
So while this might be doable for a,b,c the list would quickly grow out
of control if it were to expand from 3 possible elements to 10 or more.
Is that right?

Some constraints are better expressed in the application than in the schema.
 
G

George Bina

Hi Chris,

Yes, that is correct.
It is easy to create a more relaxed model and add these constraints at
some other level, at application level as Joe suggested or you can use
embedded Schematron rules inside XML Schema. You can find a working XML
Schema with embedded Schematron rules below.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a"/>
<xs:element name="b"/>
<xs:element name="c"/>

<xs:element name="root">
<xs:annotation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron"
name="testRootContent">
<rule context="root">
<assert test="count(a)=1">a should be used 1 time.</assert>
<assert test="count(b)=1">b should be used 1 time.</assert>
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="a"/>
<xs:element ref="b"/>
<xs:element ref="c"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Best Regards,
George
 

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
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top