Definitions and Declarations

 

There are two different types of markup in XML schemas that correspond to two parts of the specification: definitions and declarations.

Definitions create new types (simple and complex types).

Declarations describe the content models of elements and attributes. Declarations are an association between a name and the set of constraints for the specific declaration. The declarations are not types. There is a separate definition that specifies the nature of that type within the declaration.

An element whose content is a simple type can be defined in one element (such as Invoice) while elements with complex types must first be declared with two attributes, name and type. The name attribute is the name of the element; the type attribute is used to associate name with its type definition. It is the type definition that defines the content model for that type which any other element can also use. The complex type is defined as an element called complexType. It is also possible to nest the complexType element in the element declaration if it only applies to that one element, in which case the type attribute is not needed.

There are two kinds of type declarations that are used to create structures: simple declarations and complex declarations.

Simple Declarations

Simple declarations create simple types. You can create derived data types from base types. These derived types are created from types that are built into the XML Schema specification or from types that are based from another simple type.

Complex Declarations

Complex declarations create complex types. Complex types are used to describe the content model.