Search code examples
xmlxsdxsd-validationxml-validation

Union of simple types in XSD?


I have to make a simple element that can be either be an integer or a date. The element I have to use is score.

I've looked at a few links but I don't really understand.

eg: how to define xsd element with multiple option?

https://www.w3schools.com/xml/schema_simple.asp


Solution

  • Use xsd:union to create new type consisting of the union of other xs:integer and xs:date:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="score">
        <xs:simpleType>
          <xs:union memberTypes="xs:integer xs:date"/>
        </xs:simpleType>
      </xs:element>
    </xs:schema>