如何定义允许枚举值或模式匹配的模式限制?

Jim*_*eth 5 regex xsd

我正在定义一个simpleTypea restriction要么是a的值,要么是enumeration匹配a的值pattern.我意识到我可以从中做到这一切,pattern但我想要enumeration提供所提供的选项列表.

这是我期望能够做到的:

<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>
Run Code Online (Sandbox Code Playgroud)

但由于某个值无法与两个约束匹配,因此失败.如果我修改模式以允许任何枚举值,那么如果只匹配模式,它将失败.

Jim*_*eth 10

结果我需要一个union.将枚举类型定义为单独的类型:

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

  </xs:restriction>
<xs:simpleType>
Run Code Online (Sandbox Code Playgroud)

然后创建目标类型作为枚举:

<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>
Run Code Online (Sandbox Code Playgroud)

所以现在我得到选择列表,或匹配模式.正是我想要的!

更新:实际上可以将两个简单类型定义为union或通过memberTypes属性的子项.