Home > Articles > Programming > Java

XML Schemas and Datatypes

  • Print
  • + Share This
In his continuing series on using XML, David Gulbransen clarifies the sometimes complicated feature of datatyping - one of the most significant improvements to XML Schemas over DTDs.
This article is adapted from David Gulbransen's book Special Edition Using XML Schema (Que, 2001, ISBN 0-7897-2607-6).
Like this article? We recommend

Like this article? We recommend

Introducing Datatypes

One of the shortcomings of working with XML and DTDs was the lack of datatyping—the 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.

  • + Share This
  • 🔖 Save To Your Account