Overview
Schema Basics
Working with Namespaces
Complex Types
Empty Elements
Simple Content
Mixed Content
Allowing Any Content
Controlling Type Derivation
Although Document
Type Definitions can enforce basic structural rules on documents,
many applications need a more powerful and expressive validation
method. The W3C developed the XML Schema Recommendation, released on
May 2, 2001 after a long incubation period, to address these needs.
Schemas can describe complex restrictions on elements and attributes.
Multiple schemas can be combined to validate documents that use
multiple XML vocabularies. This chapter provides a rapid introduction
to key W3C XML Schema concepts and usage.
This chapter progressively introduces the structures and concepts of
XML Schemas, beginning with the fundamental structure that is common
to all schemas. The chapter begins with a very simple schema and
proceeds to add more functionality to it until ever major feature of
XML Schemas has been introduced.
A schema is a formal description of what comprises a valid document.
An XML schema is an XML document containing a formal description of
what comprises a valid XML document. A W3C XML Schema Language schema
is an XML schema written in the particular syntax recommended by the
W3C.
TIP: in those namespaces.
An
xsi:noNamespaceSchemaLocation attribute contains a URL for the
schema used to validate elements that are not in any namespace.
The
validating parser may
attempt to locate the schema using the namespace of the element
itself in one of these ways: directly by looking for a schema at that
namespace, indirectly by looking for a RDDL document at that
namespace, or implicitly by knowing in advance which schema is right
for that data-intensive applications (such
as web services using SOAP),. Unlike DTDs,
schemas can enforce specific rules about the contents of elements and
attributes. add the ability to place more
explicit restrictions on the number and sequence of child elements
that can appear in a given location. This is even true when elements
are mixed with character data, unlike the mixed content model
(#PCDATA) supported by DTDs.
WARNING:
There are a few things that DTDs do that XML Schema
can't do. Defining general entities for use in
documents is one of these.
declaring namespace-aware XML applications. Unlike DTDs (where
element and attribute declarations must include a namespace prefix),
schemas validate against the combination of the namespace URI and
local name rather than the prefixed name.
Namespaces are also used within instance documents to include directives
to the schema processor. For example, the special attributes that are
used to associate an element with a schema
(schemaLocation and
noNamespaceSchemaLocation) must be associated with
the official XML Schema instance namespace URI
() in
order for the schema processor to recognize it as an instruction to
itself.