Creating XML Schemas
Document Type Definitions have generated quite a few complaints since they were introduced. As a result, the W3C set about creating a new standard for defining a document’s structure. What the W3C created is something even more complex and flexible than DTDs: the XML Schema Definition Language.
The XML Schema Definition Language solves a number of problems posed with Document Type Definitions. For instance, because the language for specifying DTDs is inherently different from the XML document it is describing, DTDs can be difficult to read and understand. Another limitation of DTDs is the method in which data is handled. Unfortunately, DTDs only support character data types: DTDs are unable to make a dis-tinction between the various data types, such as numerics, dates, and so on. They are all considered character data types. Probably the most important and notable drawback of using DTDs is their inability to provide support for mixing elements from different docu-ments stored in separate namespaces.
Schemas, while more complex than DTDs, also give an individual much more power and control over how XML documents are validated. For instance, with the new W3C stan-dard, a document definition can specify the data type of an element’s contents, the range of values for elements, what the minimum as well as maximum number of times an ele-ment may occur, annotations to schemas, and much more.
In this chapter, we’ll cover the following topics:
The various XML data types
How to define and declare an attribute
How to define and declare simple as well as complex elements
How to create an enumerated set of values
How to specify various constraints
The different facets for the various data types
How to create groups of related elements and attributes
How to “inherit” elements and attributes from other schemas
How to define a schema for a sample purchase order XML document
How to associate and link an XML schema with an XML document