How to define a schema constraint that allows you to map an enumeration value or pattern?

I determine simpleTypewhich restrictionhas either a value from enumerationor a value corresponding to a pattern. I understand that I can make it all out pattern, but I want a list of choices that provides enumeration.

This is what I expected to do:

<xs:simpleType name="both">
  <xs:restriction base="xs:string">
    <xs:enumeration value="one" />
    <xs:enumeration value="two" />
    <xs:pattern value="[0..9]+" />
  </xs:restriction>
<xs:simpleType>

But this fails because the value cannot meet both restrictions. If I modify the pattern to allow any enumerated value, it will fail if it matches only the pattern.

+5
source share
1 answer

It turns out I need union. Define a numbered type as a separate type:

<xs:simpleType name="enumeration">
  <xs:restriction base="xs:string">
    <xs:enumeration value="one" />
    <xs:enumeration value="two" />

  </xs:restriction>
<xs:simpleType>

:

<xs:simpleType name="both">
  <xs:union memberTypes="enumeration">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:pattern value="[0..9]+" />
      </xs:restriction>
    </xs:simpleType>
  </xs:union>
</xs:simpleType>

, . , !

:. union, memberTypes.

+8

All Articles