[英]How to design the multiple choices element in xml schema?
例如,我想創建一個包含3個選項的元素Title
: Mr.
, Mrs.
, Miss
,這樣用戶只能選擇其中一個。 我怎樣才能做到這一點? 這是這樣的:
<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>
嘗試使用xs:enumeration元素。 例如,此架構限制為具有單個元素“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.