XML Schema choice 元素

xiaoxiao2025-11-26  5

XSD :

<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 version="1.0" ?> <person> <member></member> <member></member> </person> View Code

验证通过。

<?xml version="1.0" ?> <person> <employee></employee> <member></member> </person> View Code

验证通过。

<?xml version="1.0" ?> <person> <employee></employee> </person> View Code

验证失败。

 

转载请注明原文地址: https://www.6miu.com/read-5040062.html

最新回复(0)