XML schema element

<Schema> element is the root element of every XML Schema.


<Schema> element

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

<?xml version="1.0"?>

<xs:schema>
/en.
/en.
</xs:schema>

<Schema> element may contain attributes. A schema declaration often looks something like this:

<?xml version="1.0"?>

<xs:schema xmlns:xs="https://www.w3.org/2001/XMLSchema"
targetNamespace="https://w3resource.net/"
xmlns="https://w3resource.net/"
elementFormDefault="qualified">
/en.
/en.
</xs:schema>

The following code fragment:

xmlns:xs="https://www.w3.org/2001/XMLSchema"

Used in display schema elements and data types from the namespace "https://www.w3.org/2001/XMLSchema". It also sets out from the namespace "https://www.w3.org/2001/XMLSchema" elements and data types should use the prefix xs:

This snippet:

targetNamespace="https://w3resource.net/"

Display elements defined by this schema (note, to, from, heading, body) from the namespace: "https://w3resource.net/".

This snippet:

xmlns="https://w3resource.net/"

It states that the default namespace is "https://w3resource.net/".

This snippet:

elementFormDefault="qualified"

Identify any XML instance document used and the element declared in this schema must be over-defined namespace.


Schema referenced in the XML document

This XML document contains a reference to the XML Schema:

<?xml version="1.0"?>

<note xmlns="https://w3resource.net/"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://w3resource.net note.xsd">

<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The following code snippet:

xmlns="https://w3resource.net/"

It specifies a default namespace declaration. This declaration tells the schema validator that all the elements used in this XML document are declared in "https://w3resource.net/" namespace.

Once you have the XML Schema instance namespace available:

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

You can use the schemaLocation attribute. This property has two values. The first value is the namespace to use. The second value is the location for XML schema namespaces used:

xsi:schemaLocation="https://w3resource.net note.xsd"