XSD restriction for either specific string or number (mixture type)

如果在XSD restriction 上 容許 mix restriction (mix data type) 呢?
解決方法:
我們可以建立一個simpleType
之後在simpleType 入面使用 union
再把多個simpleType union 在一起
e.g.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="NumberOrSpecificString">
    <xs:union>
      <xs:simpleType>
        <xs:restriction base="xs:integer"/>
      </xs:simpleType>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="HongKong"/>
          <xs:enumeration value="London"/>
          <xs:enumeration value="Oxford"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:union>
  </xs:simpleType>
</xs:schema>

Hope you find it useful

Chi Yau
Chi Yau
Software Engineer

Interested on Learning new stuff and experience sharing