A First Look
An XML schema describes the structure of an XML instance document by defining what each element must or may contain. An element is limited by its type. For example, an element of complex type can contain child elements and attributes, whereas a simple-type element can only contain text. The diagram below gives a first look at the types of XML Schema elements.
Schema authors can define their own types or use the built-in types. Throughout this course, we will refer back to this diagram as we learn to define elements. You may want to bookmark this page, so that you can easily reference it.
The following is a high-level overview of Schema types.
- Elements can be of simple type or complex type.
- Simple type elements can only contain text. They can not have child elements or attributes.
- All the built-in types are simple types (e.g, xs:string).
- Schema authors can derive simple types by restricting another simple type. For example, an email type could be derived by limiting a string to a specific pattern.
- Simple types can be atomic (e.g, strings and integers) or non-atomic (e.g, lists).
- Complex-type elements can contain child elements and attributes as well as text.
- By default, complex-type elements have complex content, meaning that they have child elements.
- Complex-type elements can be limited to having simple content, meaning they only contain text. They are different from simple type elements in that they have attributes.
- Complex types can be limited to having no content, meaning they are empty, but they may have attributes.
- Complex types may have mixed content - a combination of text and child elements.
A Simple XML Schema
Let's take a look at a simple XML schema, which is made up of one complex type element with two child simple type elements.