Reference your type with namespace : Reference « XML Schema « XML






Reference your type with namespace


File: Data.xml

<?xml version="1.0"?>
<Books xmlns="http://www.java2s.com"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.java2s.com Schema.xsd">
        <Book>
                <Title>title 1</Title>
                <Author>author 1</Author>
                <Date>2008</Date>
                <ISBN>1-11111-111-1</ISBN>
                <Publisher>Publisher 1</Publisher>
        </Book>
        <Book>
                <Title>title 2</Title>
                <Author>author 2</Author>
                <Date>2007</Date>
                <ISBN>0-111-11111-1</ISBN>
                <Publisher>Publisher 2</Publisher>
        </Book>
        <Book>
                <Title>title 3</Title>
                <Author>author 3</Author>
                <Date>2004</Date>
                <ISBN>0-11-111111-1</ISBN>
                <Publisher>Publisher 3</Publisher>
        </Book>        
</Books>

File: Schema.xml

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.java2s.com"
        xmlns:bk="http://www.java2s.com"
        elementFormDefault="qualified">
    <element name="Books">
        <complexType>
            <sequence>
                <element ref="bk:Book" minOccurs="1" maxOccurs="unbounded"/>
            </sequence>
        </complexType>
    </element>
    <element name="Book">
        <complexType>
            <sequence>
                <element ref="bk:Title"/>
                <element ref="bk:Author"/>
                <element ref="bk:Date"/>
                <element ref="bk:ISBN"/>
                <element ref="bk:Publisher"/>
            </sequence>
        </complexType>
    </element>
    <element name="Title" type="string"/>
    <element name="Author" type="string"/>
    <element name="Date" type="string"/>
    <element name="ISBN" type="string"/>
    <element name="Publisher" type="string"/>
</schema>

 








Related examples in the same category

1.reference element
2.Reference defined data type with target namespace
3.Set minOccurs, maxOccurs for referenced types
4.Refernece anonymous complexType
5.Nexted reference
6.reference with maxOccurs
7.Use ref to remove the nested definition