Primitive and Derived Data Types

 

There are two basic kinds of data types: primitive data types and derived data types.

Primitive Data Types

Primitive data types are those that are not defined in terms of other data types. Because primitive data types are the basis for all other types, they cannot have element content or attributes. However, they can contain values. Primitive data types are built into XML schemas. Examples of primitive data types are string, float, decimal, anyURI, and QName.

For more information, see Primitive XML Data Types.

Derived Data Types

Derived data types are those that are defined in terms of other data types, called base types. Derived types may have attributes, and may have element or mixed content. Instances of derived types can contain any well-formed XML that is valid according to their data type definition. They may be built-in or user-derived. Base types can be primitive types or derived data types. Derived data types are created using extension and restriction facets. They can be built-in or user-derived data types.

New types may be derived from either a primitive type or another derived type. For example, integers are a subset of real numbers. Therefore, the XML schema integer type is derived from the decimal number type, which is its base type. You can also derive an even more restricted type of integer by using the minInclusive and maxInclusive elements. This is an example of a simple type definition.

Example

The following example shows a simpleType element that defines a derived data type, integer, that is restricted to negative values.

<simpleType name="negativeInteger">
   <restriction base="xsi:integer">
      <minInclusive value="-100" />
      <maxInclusive value="-1" />
   </restriction>
</simpleType>

As with the primitive types, the World Wide Web Consortium (W3C) has defined a set of built-in derived data types. These types are part of the W3C XML Schemas specification.

For a list of built-in derived types, see Derived XML Data Types.