枚举值的 XSD 定义 [英] XSD Definition for Enumerated Value
本文介绍了枚举值的 XSD 定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试定义一个 XSD,该 XSD 包含的字段只能具有以下三个值之一:
I'm stuck trying to define an XSD containing a field that can have only one of the following three values:
- 绿色
- 红色
- 蓝色
本质上,我想在 Schema 级别定义一个严格的枚举.
Essentially, I want to define a strict enumeration at the Schema level.
我的第一次尝试似乎是错误的,我不确定修复它的正确"方法.
My First attempt appears wrong and I'm not sure about the "right" way to fix it.
<xs:element name="color">
<xs:complexType>
<xs:choice>
<xs:element name="green"/>
<xs:element name="red"/>
<xs:element name="blue"/>
</xs:choice>
</xs:complexType>
</xs:element>
通过使用自动 XML 生成器,它将这些元素名称视为字符串对象:
By using an automatic XML generator, it treats those element names as string objects:
<xs0:color>
<xs0:green>text</xs0:green>
</xs0:color>
推荐答案
您可以在 simpleType 的上下文中定义枚举.
You can define an enumeration within the context of a simpleType.
<xs:simpleType name="color" final="restriction" >
<xs:restriction base="xs:string">
<xs:enumeration value="green" />
<xs:enumeration value="red" />
<xs:enumeration value="blue" />
</xs:restriction>
</xs:simpleType>
<xs:element name="SomeElement">
<xs:complexType>
<xs:sequence>
<xs:element name="Color" type="color" />
</xs:sequence>
</xs:complexType>
</xs:element>
这篇关于枚举值的 XSD 定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文