stevebot
stevebot

Reputation: 24005

Represent OR in XSD

I need to require

(firstName and lastName) OR (nameForDisplay)

in an XSD. I can get XOR if I use <xs:choice> but I can't seem to get OR.

Upvotes: 6

Views: 738

Answers (2)

Bill Horvath
Bill Horvath

Reputation: 1717

Here's an alternative:

<choice>
   <element name="Name" type="xs:complexType">
      <sequence>
         <element name="firstName" type="xs:String"/>
         <element name="lastName" type="xs:String"/>
      </sequence>
   </element>
   <element name="nameForDisplay" type="xs:String"/>
</choice>

Upvotes: 0

Peter Davis
Peter Davis

Reputation: 781

<choice>
  <sequence>
    <element name="firstName" />
    <element name="lastName" />
    <element name="nameForDisplay" minOccurs="0" />
  </sequence>
  <element name="nameForDisplay" />
</choice>

Ugly to have repetition, I know. You could factor out some repetition with groups.

Upvotes: 5

Related Questions