我正在定义一个simpleType
a 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
属性的子项.
归档时间: |
|
查看次数: |
2773 次 |
最近记录: |