This section describes a tutorial example on how to write the root element of the XML representation of a schema.
Now we are ready to create schema XML documents by following XML Schema specifications.
Rule 1. A schema document must be created with "schema" as the root element.
This rule is easy to follow. Here is my first test of schema XML document, empty.xsd:
<?xml version="1.0"?>
<schema>
</schema>
Let's use XsdSchemaChecker.java described in the previous section to see if empty.xsd
is a valid schema document:
>java XsdSchemaChecker empty.xsd
Error:
Line number: 2
Column number: 9
Message: s4s-elt-schema-ns: The namespace of element 'schema'
must be from the schema namespace,
'http://www.w3.org/2001/XMLSchema'.
Schema File: empty.xsd
Parser Class: com.sun.org.apache.xerces.internal.jaxp.validation
.SimpleXMLSchema
Failed with 1 errors.
Ok. We have our first syntax error which leads the second rule of schema documents.
Rule 2. The namespace of element 'schema' must be from the schema namespace,
'http://www.w3.org/2001/XMLSchema'.
There are two ways to meet this rule:
Set the default namespace with 'xmlns="http://www.w3.org/2001/XMLSchema"'
Set a namespace prefix with 'xmlns:xs="http://www.w3.org/2001/XMLSchema"',
and use it for the root element 'schema' as 'xs:schema'. Of course, you can choose any string as the prefix.
But "xs" and "xsd" are two commonly used prefix strings for the XML Schema namespace.
so we have two options to fix our first syntax error as shown below:
empty_default_namespace.xsd - Using the default namespace: