Schema Reference

After creating an XML schema document, it needs to be referenced by an XML document. The code snippet on the right displays an XML document and its referenced XML schema document.

Like DTDs, the XML schema document reference is typically positioned after the first line in the XML document and before the actual document content. The following code snippet specifies that the schemaLocation attribute can be used in the reference declaration:

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

The schemaLocation attribute specifies the location of the XML schema document. The following code snippet indicates that the XML schema document exists in the C drive of the local file system:

    xsi:schemaLocation="C:\sharedetails.xsd">

As with DTDs, an XML schema document location can be a remote site. The schemaLocation can contain a value such as:

    http://www.mydomain.com/schemas/sharedetails.xsd

XML Document
------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<ShareData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="C:\sharedetails.xsd">
<EmpName/>
<EmpNumber/>
<DeptDetails/>
<DeptID/>
</ShareData>

XML Schema Document
------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="ShareData">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="EmpName"         type="xs:string"/>
        <xs:element name="EmpNumber"         type="xs:string"/>
        <xs:element name="DeptDetails"         type="xs:string"/>
        <xs:element name="DeptID"         type="xs:string"/>
     </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Click the Next button to continue.