union types with restriction : union « XML Schema « XML






union types with restriction


File: Data.xml

<?xml version="1.0"?>
<Party xmlns="http://www.java2s.com"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.java2s.com Schema.xsd">
        <Participants>
            <Name>Item0</Name>
            <Name>Item1</Name>
        </Participants>
</Party>


File: Schema.xsd

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.java2s.com"
            xmlns="http://www.java2s.com"
            elementFormDefault="qualified">
    <xsd:simpleType name="Group0">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Item0"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="Group1">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Item1"/>
            <xsd:enumeration value="Item2"/>
            <xsd:enumeration value="Item3"/>
            <xsd:enumeration value="Item4"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="Group2">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Item5"/>
            <xsd:enumeration value="Item6"/>
            <xsd:enumeration value="Item7"/>
            <xsd:enumeration value="Item8"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="Group3">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Item9"/>
            <xsd:enumeration value="Item10"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="Group4">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Item11"/>
            <xsd:enumeration value="Item12"/>
            <xsd:enumeration value="Item13"/>
            <xsd:enumeration value="Item14"/>
            <xsd:enumeration value="Item15"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="Group5">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Item16"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="Group6">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Item17"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="CostelloFamily">
        <xsd:union memberTypes="Group0 Group1 Group2 Group3 
                                Group4 Group5 Group6"/>
    </xsd:simpleType>
    <xsd:element name="Party">
        <xsd:complexType>
             <xsd:sequence>
                 <xsd:element name="Participants">
                     <xsd:complexType>
                         <xsd:sequence>
                             <xsd:element name="Name" type="CostelloFamily" maxOccurs="unbounded"/>
                         </xsd:sequence>
                     </xsd:complexType>
                 </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

 








Related examples in the same category

1.A union datatype by reference to existing types
2.A union datatype can embed one or more elements
3.The order between derivation by list and derivation by union depends on the result to achieve
4.Union anonymous simple types
5.union with memberTypes