This section describes a tutorial example on how to use the Element Declaration Component to declare the root element for a conforming XML document.
We know that every XML document must have a root element.
So the first thing we need to do in a schema is declare a root element for the conforming XML documents.
This can be done by using an Element Declaration Schema Component, which is represented
as an XML element named as "element" in schema XML representation document.
Rule 1. A schema must have at least one Element Declaration Component to declare a root element
for the conforming XML document.
Rule 2. The XML representation of an Element Declaration Component is an "element" element,
which must have one attribute
called "name" to provide the element name for the conforming XML document.
Rule 3. The namespace of all elements used in the XML representation must be from
the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
Here is a simple schema example represented as an XML document, word.xsd
This is a very simple, but complete, schema represented as an XML document.
It declares that the conforming XML document must have a root element called "word".
Here is an example XML document, word.xml, that conforms to the schema represented in word.xsd:
<?xml version="1.0"?>
<word>
extensible
</word>
Of course, schema, word.xsd, is too simple to be useful. The "word" element must be declared with
additional properties to specify its content, attributes, and sub (child) elements. See the next section for more information.
By the way, there is nothing wrong to declare multiple root elements in a single schema document.
The following example, word_term.xsd, declares two root elements, "word" and "term":