Document Organization
Now that there is a basic schema and a valid document from
which to work, it is time to examine the structure of a schema
document and its contents. Every schema document consists of a
single root xs:schema
element. This element contains declarations for all
elements and attributes that may appear in a valid instance
document.
Tip
The XML elements that make up an XML Schema must belong to
the XML Schema namespace (http://www.w3.org/2001/XMLSchema
), which
is frequently associated with the xs
: prefix. For the remainder of this
chapter, all schema elements will be written using the xs
: prefix to indicate that they belong
to the Schema namespace.
Instance elements declared using top-level xs:element
elements in the schema
(immediate child elements of the xs:schema
element) are considered
global elements. For example, the simple schema in
Example 17-2 globally
declares one element: fullName
.
According to the rules of schema construction, any element that is
declared globally may appear as the root element of an instance
document.
In this case, since only one element has been declared, that shouldn’t be a problem. But when building more complex schemas, this side effect must be taken into consideration. If more than one element is declared globally, a schema-valid document may not contain the root element you expect.
Naming conflicts are another potential problem with multiple global declarations. When writing schema declarations, it is an error to declare two things ...
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.