XML Schemas and Datatypes
- Introducing Datatypes
- Primitive Datatypes
- Constraining Facets
- Built-in Derived Datatypes
- Defining Your Own Datatypes
Introducing Datatypes
One of the shortcomings of working with XML and DTDs was the lack of datatypingthe ability to constrain the content of elements and attributes to specific types of data beyond the level offered by enumerations and basic content models.
As information management becomes more sophisticated in an organization, most quickly adopt database technology to manage large amounts of data; from customer information to sales figures to parts lists, databases are useful and prevalent. Enter XML, which is a fantastic format for exchanging data between applications easily and efficiently; suddenly you're faced with issues surrounding how to handle your XML data in conjunction with databases.
Similarly, you may have specific types of information in your XML files that need to be formatted precisely to ensure compatibility; for example, the date field for an invoice document or a decimal value for currency amounts.
Both of these problems can be addressed through the use of datatypes with XML Schemas, which allow you to assign a datatype to an element or attribute. With the element or attribute restricted to a certain datatype, the authors of instance documents are then restricted to using values that comply with the datatypes you have defined.
The XML Schemas Part 2: Datatypes Recommendation defines how datatypes are addressed in XML Schemas. The Recommendation defines a number of primitive datatypes, which can be used on their own or serve as the basis for deriving new datatypes.