different types with the same name : Salami Slice « XML Schema « XML






different types with the same name


File: Data.xml

<?xml version="1.0"?>
<BookOnCars xmlns="http://www.java2s.com"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation=
                              "http://www.java2s.com
                               ScopeTest.xsd">
        <Chapter>
                <Title>title</Title>
                <Section>
                    <Title>title</Title>
                </Section>
        </Chapter>
        <Title>A car</Title>
</BookOnCars>

File: ScopeTest.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:element name="BookOnCars">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="Chapter">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="Title" type="xsd:string"/>
                            <xsd:element name="Section">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="Title" type="xsd:string"/>
                                    </xsd:sequence>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="Title" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:complexType name="Title">
        <xsd:sequence> 
            <xsd:element name="CarManufacturer" type="xsd:string"/>
            <xsd:element name="Year" type="xsd:gYear"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="Title" type="xsd:string"/>
    <xsd:attribute name="Title" type="xsd:string"/>
</xsd:schema>

 








Related examples in the same category

1.Salami Slice Design
2.Reuse complex type
3.Global attibute definitions
4.Ref and Salami Slice
5.Reuse data type defined
6.Reuse data type defined in another xml schema file
7.Schema for XSchema elements