Schemas Versus DTDs
DTDs provide the capability to do basic validation of the following items in XML documents:
Element nesting
Element occurrence constraints
Permitted attributes
Attribute types and default values
However, DTDs do not provide fine control over the format and
data types of element and attribute values. Other than the various
special attribute types (ID
,
IDREF
, ENTITY
, NMTOKEN
, and so forth), once an element or
attribute has been declared to contain character data, no limits may
be placed on the length, type, or format of that content. For
narrative documents (such as web pages, book chapters, newsletters,
etc.), this level of control is probably good enough.
But as XML makes inroads into more record-like applications, such as remote procedure calls and object serialization, more precise control over the text content of elements and attributes becomes important. The W3C XML Schema standard includes the following features:
Simple and complex data types
Type derivation and inheritance
Element occurrence constraints
Namespace-aware element and attribute declarations
The most important of these features is the addition of simple
data types for parsed character data and attribute values. Schemas
can enforce much more specific rules about the contents of elements
and attributes than DTDs can. In addition to a wide range of
built-in simple types (such as string
, integer
, decimal
, and dateTime
), the schema language provides a framework for declaring new data types, deriving new types ...
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.