Skip to main content

XSD: The <schema> element

The <schema> element is the root element of every XML Schema. Let's see how use it.

The <schema> element

The <schema> element is the root element of every XML Schema:

<?xml version="1.0"?>  


The <schema> element may contain some attributes. For example:



  • xmlns:xs="" indicates that the elements and data types used in the schema come from the namespace. It also specifies that the elements and data types that come from the namespace should be prefixed with :xs.
  • targetNamespace="" indicates that the elements defined by this schema (note, to, from, heading, body.) come from the namespace.
  • xmlns="" indicates that the default namespace is
  • elementFormDefault="qualified" indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.

elementFormDefault can be qualified or unqualified:

  • qualified elements and attributes are in the targetNamespace of the schema
  • unqualified elements and attributes do not have a namespace

Referencing a Schema in an XML Document

This XML document has a reference to an XML Schema:

xsi:schemaLocation=" book.xsd">
<title>A Great Book</title>
<author>Tom Nolan</author>
<publisher>Tutorial Reference</publisher>


  • xmlns="" specifies the default namespace declaration. This declaration tells to the schema-validator that all the elements used in this XML document are declared in the" namespace.
  • xmlns:xsi="" declares a standard namespace prefix (xsi) for a core namespace used in the XML schema
  • xsi:schemaLocation=" book.xsd" The schemaLocation attribute has two values separated by a space: the first is the name space to use while the second value is the location of the XML schema to use for that namespace.