xmlxsdrestriction

XSD - extend base restriction type


I've the following type definitions:

<xsd:simpleType name="T_YES_NO">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="y" />
    <xsd:enumeration value="n" />
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="T_FORBIDDEN">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="f" />
  </xsd:restriction>
</xsd:simpleType>

I would like to restrict a type T_FOOBAR as

<xsd:simpleType name="T_FOOBAR">
  <xsd:restriction base="T_YES_NO" />
  <xsd:restriction base="T_FORBIDDEN" /> <!-- Not allowed -->
</xsd:simpleType>

and I don't want to write

<xsd:simpleType name="T_FOOBAR">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="y" />
    <xsd:enumeration value="n" />
    <xsd:enumeration value="f" />
  </xsd:restriction>
</xsd:simpleType>

How to do that?


Solution

  • It sounds as if you could solve this particular use case with a union type: https://www.w3.org/TR/xmlschema-0/#UnionDt.

    <xsd:simpleType name="T_FOOBAR">
      <xsd:union memberTypes="T_YES_NO T_FORBIDDEN"/>
    </xsd:simpleType>