WebReference.com - Part 1 of Chapter 1: Professional XML Schemas, from Wrox Press Ltd (4/5) | WebReference

WebReference.com - Part 1 of Chapter 1: Professional XML Schemas, from Wrox Press Ltd (4/5)

To page 1To page 2To page 3current pageTo page 5
[previous] [next]

Professional XML Schemas

The Difference Between Simple and Complex Types

There are two kinds of type in XML Schema: simple types and complex types, both of which constrain the allowable content of an element or attribute:

Let's have a closer look at what this means.

Simple Types

All attribute values and text-only element content simply consists of strings of characters. The ability for XML Schema to support datatypes means that we can place restrictions on the characters that can appear in attribute values and text-only element content.

An example of such a restriction is the representation of a Boolean value, in which case XML Schema only allows the character strings: true, false, 1, or 0. After all, an instance document should not be allowed to use values such as "maybe" or "4" in attributes or elements that are supposed to represent a Boolean value. Alternatively, if we wanted to represent a byte, we would only want characters that are an integer whose value is between –128 and 127, so that 1445 would not be allowed and neither would ff23.

An XML Schema aware processor is required to support a number of built-in simple types that are considered common in programming languages and databases, and a number of datatypes that the working group thought were important to XML document authors. This is why we were allowed to specify that the content of the FirstName, MiddleInital, and LastName elements were strings (which places very little restriction on the allowable text of the element content):

   <element name = "FirstName" type = "string" />
   <element name = "MiddleInitial" type = "string" />
   <element name = "LastName" type = "string" />

In addition to the built-in simple types, XML Schema allows us to derive our own simple types that restrict the allowable content of the built-in simple types already defined in XML Schema.

We will look into all of the built-in simple types in the next chapter. The rest of this chapter will stick to using the built-in types of string, date, and integer.


To page 1To page 2To page 3current pageTo page 5
[previous] [next]

Created: October 18, 2001
Revised: October 18, 2001


URL: http://webreference.com/authoring/languages/xml/schemas/chap1/1/4.html