import schema and elementFormDefault : import « XML Schema « XML






import schema and elementFormDefault


File: Data.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Books.xsl"?>
<Books xmlns="http://www.java2s.com"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation=
                          "http://www.java2s.com
                           Books.xsd">
        <Book xmlns="http://www.java.org">
                <Title>title1</Title>
                <Author>author1</Author>
                <Date>1998</Date>
                <ISBN>1-11111-111-1</ISBN>
                <Publisher>publisher1</Publisher>
        </Book>
        <Book xmlns="http://www.java2s.org">
                <Title>title2</Title>
                <Author>author2</Author>
                <Date>1977</Date>
                <ISBN>2-222-22222-2</ISBN>
                <Publisher>publisher2</Publisher>
        </Book>
</Books>


File: Books.xsd

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.java2s.com"
        xmlns:bk="http://www.demo2s.com"
        elementFormDefault="qualified">

    <import namespace="http://www.demo2s.com"
            schemaLocation="Book.xsd"/>

    <element name="Books">
        <complexType>
            <sequence>
                <element ref="bk:Book" maxOccurs="unbounded"/>
            </sequence>
        </complexType>
    </element>
</schema>

File: Book.xsd

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.demo2s.com"
            elementFormDefault="qualified">
    <element name="Book">
        <complexType>
            <sequence>
                <element name="Title" type="string"/>
                <element name="Author" type="string"/>
                <element name="Date" type="gYear"/>
                <element name="ISBN" type="string"/>
                <element name="Publisher" type="string"/>
            </sequence>
        </complexType>
    </element>
</schema>

 








Related examples in the same category

1.import another XML schema
2.import with namespace