0

例如,我想创建一个Title包含 3 个选项的元素: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>
4

1 回答 1

2

尝试使用 xs:enumeration 元素。例如,此模式限制为具有单个元素“标题”的文档,其中包含“先生”或“女士”:

<?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>
于 2013-07-26T20:32:40.360 回答