XOR in XSD

In my XSD,  i've got two elements, I want at most 1 of either, and at least 1 of them.
In other words I want : a, ab, abc, b,ba,bc, etc..  but not aa or bb, etc or nothing.
I tried:
    <xs:complexType name="xType">
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element ref="a"/>
            <xs:element ref="b"/>
            <xs:element ref="c"/>
        </xs:choice>
    </xs:complexType>

but this doesnt allow ab, etc

and
<xs:complexType name="xType">
       <xs:choice minOccurs="1" maxOccurs="unbounded">
           <xs:element ref="a" maxOccurs="1"/>
           <xs:element ref="b" maxOccurs="1"/>
           <xs:element ref="c" maxOccurs="1"/>
       </xs:choice>
   </xs:complexType>

but this allows aa,bb etc..

I also tried:
    <xs:complexType name="xType">
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="a" minOccurs="0" maxOccurs="1"/>
            <xs:element name="b" minOccurs="0" maxOccurs="1"/>
            <xs:element name="c" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>

But this doesn't enforce the non-empty condtion.

How can this requirement be implemented in XSD?
LVL 5
blackfrancis75Asked:
Who is Participating?
 
Geert BormansInformation ArchitectCommented:
by implementing the different options, the risk of combining xs:all and xs:choice will make your model ambiguous soon,
so your best bet is giving the options by combining sequences and choices and do that carefully

(a, (b? & c?)) | (b, (a? & c?)) | (c, (b? & a?))

is unambiguous, gives at least one element, up to three and no element is allowed twice
You can vary on this theme to get what you want

In my opinion it is better to model as an xs:choice multiple times
(a | b | c)+
makes sure that you have at least one element in the content model
and use schematron for restricting (www.Schematron.com)
in the restricting assertions you can say something like
"count(a) <= 1 and count(b) <= 1 and count(c) <= 1"
that should cover your requirement
0
 
Geert BormansInformation ArchitectCommented:
in short:
your only option, without bringing schematron in the picture, is listing all permutations one way or another
I would go the schematron route by the way
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.