Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML schema Element

XSD - Element


The element is the root element of every XML Schema.


Element

The element is the root element of every XML Schema:

xs:schema

...

...

An element can contain attributes. A schema declaration often looks something like this:

targetNamespace="http://www.runoob.com"

xmlns="http://www.runoob.com"

elementFormDefault="qualified">

...

...

The following code snippet:

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

shows that the elements and data types used in the schema come from the namespace "http://www.w3.org/2001/XMLSchema". It also specifies that elements and data types from the namespace "http://www.w3.org/2001/XMLSchema" should use the prefix xs:

This snippet:

targetNamespace="http://www.runoob.com"

shows that the elements defined by this schema (note, to, from, heading, body) come from the namespace: "http://www.runoob.com".

This snippet:

xmlns="http://www.runoob.com"

indicates that the default namespace is "http://www.runoob.com".

This snippet:

elementFormDefault="qualified"

indicates that any elements used in an XML instance document and declared in this schema must be namespace-qualified.


Referencing a Schema in an XML Document

This XML document contains a reference to an XML Schema:

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

xsi:schemaLocation="http://www.runoob.com note.xsd">

Tove

Jani

Reminder

Don't forget me this weekend!

The following code snippet:

xmlns="http://www.runoob.com"

specifies the declaration of the default namespace. This declaration tells the schema validator that all elements used in this XML document are declared in the namespace "http://www.runoob.com".

Once you have an available XML Schema instance namespace:

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

you can use the schemaLocation attribute. This attribute has two values. The first value is the namespace to be used. The second value is the location of the XML schema for that namespace:

xsi:schemaLocation="http://www.runoob.com note.xsd"