[英]How to design the multiple choices element in xml schema?
For example, I want to create an element Title
containing 3 choices: Mr.
, Mrs.
, Miss
, so that users can only choose one of them. 例如,我想创建一个包含3个选项的元素Title
: Mr.
, Mrs.
, Miss
,这样用户只能选择其中一个。 How can I do that? 我怎样才能做到这一点? Is this something like: 这是这样的:
<xs:complexType name="Title">
<xs:sequence>
<xs:choice maxOccurs="unbounded" minOccurs="0">
Mr.
</xs:choice>
<xs:choice maxOccurs="unbounded" minOccurs="0">
Mrs.
</xs:choice>
<xs:choice maxOccurs="unbounded" minOccurs="0">
Miss
</xs:choice>
</xs:sequence>
</xs:complexType>
Try using the xs:enumeration element. 尝试使用xs:enumeration元素。 For example this schema restricts to documents with a single element 'Title' with 'Mr' or 'Ms' in it: 例如,此架构限制为具有单个元素“Title”且其中包含“Mr”或“Ms”的文档:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Title" type="Title"/>
<xs:simpleType name="Title">
<xs:restriction base="xs:string">
<xs:enumeration value="Mr"/>
<xs:enumeration value="Ms"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.