天天看点

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/

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出,

原文链接

如果觉的博主写的可以,收到您的赞会是很大的动力,如果您觉的不好,您可以投反对票,但麻烦您留言写下问题在哪里,这样才能共同进步。谢谢!