天天看點

XML Schema choice 元素

XSD :

XML Schema choice 元素
XML Schema choice 元素

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron" elementFormDefault="qualified">
<xsd:simpleType name="employee">
    <xsd:restriction base="xsd:string">    
    </xsd:restriction>
  </xsd:simpleType>
 <xsd:simpleType name="member">
     <xsd:restriction base="xsd:string">
    </xsd:restriction>
  </xsd:simpleType>
<xsd:element name="person">
  <xsd:complexType>
    <xsd:choice minOccurs="2" maxOccurs="2">
      <xsd:element name="employee" type="employee"/>
      <xsd:element name="member" type="member"/>
    </xsd:choice>
  </xsd:complexType>
</xsd:element>
</xsd:schema>      

View Code

minOccurs="2" maxOccurs="2" 用于限定 choice裡面元素在父元素中出現的次數。

Example:

XML Schema choice 元素
XML Schema choice 元素
<?xml version="1.0" ?>
<person>
<member></member>
<member></member>
</person>      

驗證通過。

XML Schema choice 元素
XML Schema choice 元素
<?xml version="1.0" ?>
<person>
<employee></employee>
<member></member>
</person>      
XML Schema choice 元素
XML Schema choice 元素
<?xml version="1.0" ?>
<person>
<employee></employee>
</person>      

驗證失敗。

作者:

HarlanC

部落格位址:

http://www.cnblogs.com/harlanc/

個人部落格:

http://www.harlancn.me/

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出,

原文連結

如果覺的部落客寫的可以,收到您的贊會是很大的動力,如果您覺的不好,您可以投反對票,但麻煩您留言寫下問題在哪裡,這樣才能共同進步。謝謝!