xml An Example of XSD Document


Example

An XSD that describe a contact information about a company is given below.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://NamespaceTest.com/CommonTypes"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  elementFormDefault="qualified">
<xs:element name="contact">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="name" type="xs:string" />
            <xs:element name="company" type="xs:string" />
            <xs:element name="phone" type="xs:int" />
        </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

In the above example the attributes in second line

<xs:schema targetNamespace="http://NamespaceTest.com/CommonTypes" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

Attributes 'targetnamespace' and elementFormDefault are optional.