Arguing with Angle Brackets: A Step-by-Step Introduction to XML Schema
XML technology is now widespread, used from databases to web pages and everything in between. As developers, we need to be aware of not only how to use XML, but how to constrain it to convey meaningful information. The primary building block for XML is the W3C's XML Schema language. However, while XML Schema is powerful, it's also more than a little tricky to come to terms with at first. To help you to beat XML Schema into submission, this article uses simple examples to describe step by step how to use XML Schema to build platform-independent data models.
With the exception of XML itself, XML Schema is the single most important technology in the XML family. XML Schema is a W3C recommendation that provides a platform-independent type system and structuring mechanism for XML documents.
XML documents that conform to a schema are known as instance documents, in the same way that objects of a particular class are known as instances. Thus we can conceptually match XML Schema schemas with classes and XML documents with objects, as shown in Figure 1.
Figure 1 Comparing XML to an object-oriented model.
Whereas in object-based systems, classes and their interrelationships provide the blueprint for the creation and manipulation of objects, in the XML arena the type model expressed in XML Schema schemas constrains documents that confirm to those schemas.
Like object-oriented programming languages, XML Schema provides a number of built-in types and allows these types to be extended in a variety of ways to build abstractions appropriate for particular problem domains. Each XML Schema type is represented as the set of (textual) values that instances of that type can take. For example, the boolean type can only take values of true and false, whereas the short type can take any value from -32768 to 32767, inclusive. In fact, XML Schema provides 44 different built-in types, specified in the http://www.w3.org/2001/XMLSchema namespace. XML Schema even allows users to develop their own types; in fact, extending and manipulating types to create content models is the very heart of XML Schema.