2.3. First Findings
Even in this very simple schema, we have learned a lot about what W3C XML Schema has to offer.
2.3.1. W3C XML Schema Is Modular
In this example, we defined simple components (elements and attributes in this case, but we will see in the next chapters how to define other kinds of components) that we used to build more complex components. This is one of the key principles that have guided the editors of W3C XML Schema. These editors have borrowed many concepts of object-oriented design to develop complex components.
If we draw a parallel between datatypes and classes, the elements and attributes can be compared to objects. Each of the component definitions that we included in our first schema is similar to an object. Referencing one of these components to build a new element is similar to creating a new object by cloning the already defined component.
In the next chapters, we will see how we can also create the components "in place" (where they are needed) as well as create datatypes from which we can derive elements and attributes the same way we can instantiate a class to create an object.
2.3.2. W3C XML Schema Is Both About Structure and Datatyping
Note also that W3C XML Schema is pursuing two different levels of validation in this first example: we have defined both rules about the structure of the document and rules above the content of leaf nodes of the document. The W3C Recommendation makes a clear distinction between these two levels by publishing the recommendation in two parts (Part 1: Structures and Part 2: Datatypes), which are relatively independent.
There is also a big difference between simple types, which are about datatyping and constraining the content of leaf nodes in the tree structure of an XML document, and complex types, which are about defining the structure of a document.
2.3.3. Flat Design, Global Components
Finally, note the flatness of this schema: each component (element or attribute) is defined directly under the xs:schema document element.
Components defined directly under the xs:schema document element are called "global" components. These have a couple of notable properties: they can be referenced anywhere in the schema as well as in the other schema that may include or import this schema (we will see in the next chapters how to import or include schemas), and all the global elements can be used as document root elements.
Copyright © 2002 O'Reilly & Associates. All rights reserved.