XML Schema Data Types | Generated by AI

Home PDF

XML Schema defines a rich set of built-in data types that can be used to specify the kind of data allowed in elements and attributes. These data types ensure that the XML content adheres to the intended format and constraints.

The built-in data types in XML Schema are broadly categorized into primitive and derived types. Derived types are based on primitive types and are created by applying restrictions or other modifications.

Primitive Data Types (19 built-in):

These are the fundamental, indivisible data types from which all other built-in and user-defined simple types are derived.

Derived Data Types (around 25 built-in):

These data types are derived from the primitive types by applying constraints (facets) such as length, range, patterns, etc.

Derived from string:

Derived from decimal:

Other Derived Types:

User-Defined Data Types:

In addition to the built-in types, XML Schema allows you to define your own simple and complex data types using mechanisms like:

When defining elements and attributes in an XML Schema, you use the type attribute to specify which data type the content should adhere to. This ensures data validity and facilitates data processing.

For example:

<xs:element name="age" type="xs:positiveInteger"/>
<xs:element name="name" type="xs:string"/>
<xs:attribute name="status" type="xs:token"/>

In this snippet, the age element is defined to hold a positive integer, the name element a string, and the status attribute a token (a normalized string with specific whitespace handling).

Understanding these data types is fundamental to creating effective and well-defined XML Schemas. You can find the complete details and formal definitions in the W3C XML Schema Part 2: Datatypes specification.


Back 2025.03.29 Donate