Search code examples
xmlxsdxsd-validation

XML validation to require an element if another is not provided - without XSD 1.1


Preferably without using XSD 1.1 - require an XML element if another is not provided and vice versa.

Say I have a Job element:

<Job>
  <Ref>""</JobReferenceId>
  <Title>""</JobTitle>
  <Type>""</Type>
  <Contract>""</Contract>
</Job>

Type should be a required element if Contract is not provided and Contract should be a required element if Type is not provided. Both shouldn't be provided together.

Can I do this without XSD 1.1?


Solution

  • Sounds like a straightforward xs:choice:

    xs:sequence
      xs:element name="Ref"
      xs:element name="Title"
      xs:choice
         xs:element name="Type"
         xs:element name="Contract"