Union anonymous simple types : union « XML Schema « XML






Union anonymous simple types

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>
            <Name>Item2</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="CostelloFamily">
        <xsd:union>
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="Item0"/>
                </xsd:restriction>
            </xsd:simpleType>
            <xsd:simpleType>
                <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>
                <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>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="Item9"/>
                    <xsd:enumeration value="Item10"/>
                </xsd:restriction>
            </xsd:simpleType>
            <xsd:simpleType>
                <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>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="Item16"/>
                </xsd:restriction>
            </xsd:simpleType>
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="Item17"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:union>
    </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 types with restriction
5.union with memberTypes