W3C

XML Schema Part 2: Datatypes

W3C Working Draft 07 April 2000

This version:
http://www.w3.org/TR/2000/WD-xmlschema-2-20000407/
(in XML and HTML, with a schema and DTD including datatype definitions, as well as a schema for built-in datatypes only, in a separate namespace.)
Latest version:
http://www.w3.org/TR/xmlschema-2/
Previous version:
http://www.w3.org/TR/2000/WD-xmlschema-2-20000225/
Editors:
Paul V. Biron (Kaiser Permanente, for Health Level Seven) <Paul.V.Biron@kp.org>
Ashok Malhotra (IBM) <petsa@us.ibm.com>

Copyright ©1999-2000 W3C® (MIT, INRIA, Keio), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.


Abstract

XML Schema: Datatypes is part 2 of a two-part draft of the specification for the XML Schema definition language. This document proposes facilities for defining datatypes to be used in XML Schemas and other XML specifications. The datatype language, which is itself represented in XML 1.0, provides a superset of the capabilities found in XML 1.0 document type definitions (DTDs) for specifying datatypes on elements and attributes.

Status of this document

This is the Last-Call public working draft of XML Schema 1.0, issued by the XML Schema Working Group, for review by the public and by members and working groups of the World Wide Web Consortium.

This working draft incorporates all Working Group decisions through 2000-04-06. It has been reviewed by the XML Schema Working Group, and the Working Group has agreed to its publication as a Last Call draft. The Last Call period is expected to end 12 May 2000. Following this Last Call for Review, the Working Group intends to submit this specification for publication as a Candidate Recommendation.

This schedule may vary, depending on the comments of the public and of other W3C working groups on this draft. Such comments are instrumental in the WG's deliberations, and we encourage readers to review the draft and to send comments to www-xml-schema-comments@w3.org. An archive of the comments received is available.

Although the Working Group does not anticipate further changes to the functionality described here, this is still a working draft, subject to change. The present version should be implemented only by those interested in providing a check on its design or by those preparing for an implementation of the Candidate Recommendation. The Schema WG will not allow early implementation to constrain its ability to make changes to this specification prior to final release.

A list of current W3C working drafts can be found at http://www.w3.org/TR/. They may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress".

Several "note types" are used throughout this draft:

issue [Issue (issue-name): ]
something on which the editors are seeking comment.
editorial note [Ed. Note: ]
something the editors wish to call to the attention of the reader. To be removed prior to the recommendation becoming final.
note [Note: ]
something the editors wish to call to the attention of the reader. To remain in the final recommendation.

Table of contents

1 Introduction
    1.1 Purpose
    1.2 Requirements
    1.3 Scope
    1.4 Terminology
    1.5 Constraints and Contributions
2 Type System
    2.1 Datatype
    2.2 Value space
    2.3 Lexical space
    2.4 Facets
        2.4.1 Fundamental facets
        2.4.2 Constraining or Non-fundamental facets
    2.5 Datatype dichotomies
        2.5.1 Atomic vs. list datatypes
        2.5.2 Primitive vs. derived datatypes
        2.5.3 Built-in vs. user-derived datatypes
3 Built-in datatypes
    3.1 Namespace considerations
    3.2 Primitive datatypes
        3.2.1 string
        3.2.2 boolean
        3.2.3 float
        3.2.4 double
        3.2.5 decimal
        3.2.6 timeDuration
        3.2.7 recurringDuration
        3.2.8 binary
        3.2.9 uriReference
        3.2.10 ID
        3.2.11 IDREF
        3.2.12 ENTITY
        3.2.13 NOTATION
        3.2.14 QName
    3.3 Derived datatypes
        3.3.1 language
        3.3.2 IDREFS
        3.3.3 ENTITIES
        3.3.4 NMTOKEN
        3.3.5 NMTOKENS
        3.3.6 Name
        3.3.7 NCName
        3.3.8 integer
        3.3.9 nonPositiveInteger
        3.3.10 negativeInteger
        3.3.11 long
        3.3.12 int
        3.3.13 short
        3.3.14 byte
        3.3.15 nonNegativeInteger
        3.3.16 unsignedLong
        3.3.17 unsignedInt
        3.3.18 unsignedShort
        3.3.19 unsignedByte
        3.3.20 positiveInteger
        3.3.21 timeInstant
        3.3.22 time
        3.3.23 timePeriod
        3.3.24 date
        3.3.25 month
        3.3.26 year
        3.3.27 century
        3.3.28 recurringDate
        3.3.29 recurringDay
4 Datatype components
    4.1 Datatype definition
    4.2 Constraining facets
        4.2.1 length
        4.2.2 minLength
        4.2.3 maxLength
        4.2.4 pattern
        4.2.5 enumeration
        4.2.6 maxInclusive
        4.2.7 maxExclusive
        4.2.8 minExclusive
        4.2.9 minInclusive
        4.2.10 precision
        4.2.11 scale
        4.2.12 encoding
        4.2.13 duration
        4.2.14 period
5 XML representation of datatype definitions
    5.1 XML representation of datatype definitions
        5.1.1 Derivation by restriction
        5.1.2 Derivation by list
    5.2 Constraining facets
        5.2.1 length
        5.2.2 minLength
        5.2.3 maxLength
        5.2.4 pattern
        5.2.5 enumeration
        5.2.6 maxInclusive
        5.2.7 maxExclusive
        5.2.8 minInclusive
        5.2.9 minExclusive
        5.2.10 precision
        5.2.11 scale
        5.2.12 encoding
        5.2.13 duration
        5.2.14 period
6 Conformance

Appendices

A Schema for Datatype Definitions (normative)
B DTD for Datatype Definitions (normative)
C Datatypes and Facets
    C.1 Fundamental Facets
    C.2 Constraining Facets
D ISO 8601 Date and Time Formats
    D.1 ISO 8601 Conventions
    D.2 Truncated and Reduced Formats -- Changed Heading for Section
    D.3 Deviations from ISO 8601 Formats
        D.3.1 Sign Allowed
        D.3.2 More Than 9999 Years
E Regular Expressions
    E.1 Character Classes
        E.1.1 Character Class Escapes
F References
    F.1 Normative
    F.2 Non-normative
G Acknowledgments (non-normative)
H Revisions from Previous Draft

1 Introduction

1.1 Purpose

The [XML 1.0 Recommendation] specification defines limited facilities for applying datatypes to document content in that documents may contain or refer to DTDs that assign types to elements and attributes. However, document authors, including authors of traditional documents and those transporting data in XML, often require a higher degree of type checking to ensure robustness in document understanding and data interchange.

The table below offers two typical examples of XML instances in which datatypes are implicit: the instance on the left represents a billing invoice, the instance on the right a memo or perhaps an email message in XML.

Data oriented Document oriented
<invoice>
   <orderDate>1999-01-21</orderDate>
   <shipDate>1999-01-25</shipDate>
   <billingAddress>
      <name>Ashok Malhotra</name>
      <street>123 IBM Ave.</street>
      <city>Hawthorne</city>
      <state>NY</state>
      <zip>10532-0000</zip>
   </billingAddress>
   <voice>555-1234</voice>
   <fax>555-4321</fax>
</invoice>
<memo importance='high'
      date='1999-03-23'>
   <from>Paul V. Biron</from>
   <to>Ashok Malhotra</to>
   <subject>Latest draft</subject>
   <body>
      We need to discuss the latest
      draft <emph>immediately</emph>.
      Either email me at <email>
      mailto:paul.v.biron@kp.org</email>
      or call <phone>555-9876</phone>
   </body>
</memo>

The invoice contains several dates and telephone numbers, the postal abbreviation for a state (which comes from an enumerated list of sanctioned values), and a ZIP code (which takes a definable regular form). The memo contains many of the same types of information: a date, telephone number, email address and an "importance" value (from an enumerated list, such as "low", "medium" or "high"). Applications which process invoices and memos need to raise exceptions if something that was supposed to be a date or telephone number does not conform to the rules for valid dates or telephone numbers.

In both cases, validity constraints exist on the content of the instances that are not expressible in XML DTDs. The limited datatyping facilities in XML have prevented validating XML processors from supplying the rigorous type checking required in these situations. The result has been that individual applications writers have had to implement type checking in an ad hoc manner. This specification addresses the need of both document authors and applications writers for a robust, extensible datatype system for XML which could be incorporated into XML processors. As discussed below, these datatypes could be used in other XML-related standards as well.

1.2 Requirements

The [XML Schema Requirements] document spells out concrete requirements to be fulfilled by this specification, which state that the XML Schema Language must:

  1. provide for primitive data typing, including byte, date, integer, sequence, SQL & Java primitive data types, etc.;
  2. define a type system that is adequate for import/export from database systems (e.g., relational, object, OLAP);
  3. distinguish requirements relating to lexical data representation vs. those governing an underlying information set;
  4. allow creation of user-defined datatypes, such as datatypes that are derived from existing datatypes and which may constrain certain of its properties (e.g., range, precision, length, format).

1.3 Scope

This portion of the XML Schema Language discusses datatypes that can be used in an XML Schema. These datatypes can be specified for element content that would be specified as #PCDATA and attribute values of various types in a DTD. It is the intention of this specification that it be usable outside of the context of XML Schemas for a wide range of other XML-related activities such as [XSL] and [RDF Schema].

1.4 Terminology

The terminology used to describe XML Schema Datatypes is defined in the body of this specification. The terms defined in the following list are used in building those definitions and in describing the actions of a datatype processor:

[Definition:]   for compatibility
A feature of this specification included solely to ensure that schemas which use this feature remain compatible with [XML 1.0 Recommendation]
[Definition:]  may
Conforming documents and processors are permitted to but need not behave as described.
[Definition:]  match
(Of strings or names:) Two strings or names being compared must be character for character the same.
[Definition:]  must
Conforming documents and processors are required to behave as described; otherwise they are in error.
[Definition:]  error
A violation of the rules of this specification; results are undefined. Conforming software may detect and report an error and may recover from it.

1.5 Constraints and Contributions

This specification provides three different kinds of normative statements about schema components, their representations in XML and their contribution to the schema-validation of information items:

[Definition:]   Constraint on Schemas
Constraints on the schema components themselves, i.e. conditions components must satisfy to be components at all. Largely to be found in Datatype components (§4).
[Definition:]   Schema Representation Constraint
Constraints on the representation of schema components in XML. Some but not all of these are expressed in Schema for Datatype Definitions (normative) (§A) and DTD for Datatype Definitions (normative) (§B). Largely to be found in XML representation of datatype definitions (§5).
[Definition:]   Validity Contribution
Constraints expressed by schema components which information items must satisfy to be schema-valid. Largely to be found in Datatype components (§4).

2 Type System

This section describes the conceptual framework behind the type system defined in this specification. The framework has been influenced by the [ISO 11404] standard on language-independent datatypes as well as the datatypes for [SQL] and for programming languages such as Java.

The datatypes discussed in this specification are computer representations of well known abstract concepts such as integer and date. It is not the place of this specification to define these abstract concepts; many other publications provide excellent definitions.

2.1 Datatype

[Definition:]  In this specification, a datatype is a 3-tuple, consisting of a) a set of distinct values, called its value space, b) a set of lexical representations, called its lexical space, and c) a set of facets that characterize properties of the value space, individual values or lexical items.

2.2 Value space

[Definition:]  A value space is the set of values for a given datatype. Each value in the value space of a datatype is denoted by one or more literals in its lexical space.

The value space of a given datatype can be defined in one of the following ways:

value spaces have certain properties. For example, they always have the property of cardinality, some definition of equality and may be ordered by which individual values within the value space can be compared to one another. The properties of value spaces that are recognized by this specification are defined in Fundamental facets (§2.4.1).

2.3 Lexical space

In addition to its value space, each datatype also has a lexical space.

[Definition:]  A lexical space is the set of valid literals for a datatype (literals may appear as one or more character information items as defined in [XML Information Set]).

For example, "100" and "1.0E2" are two different literals from the lexical space of float which both denote the same value. The type system defined in this specification provides a mechanism for schema designers to control the set of values and the corresponding set of acceptable literals of those values for a datatype.

2.4 Facets

[Definition:]  A facet is a single defining aspect of a value space. Generally speaking, each facet characterizes a value space along independent axes or dimensions.

The facets of a datatype serve to distinguish those aspects of one datatype which differ from other datatypes. Rather than being defined solely in terms of a prose description the datatypes in this specification are defined in terms of the synthesis of facet values which together determine the value space and properties of the datatype.

Facets are of two types: fundamental facets that define the datatype and non-fundamental or constraining facets that constrain the permitted values of a datatype.

2.4.1 Fundamental facets

[Definition:]   A fundamental facet is an abstract property which serves to semantically characterize the values of a value space.

These properties are discussed in this section.

2.4.1.1 Equal

Every value space supports the notion of equality, with the following rules:

  • for any two instances of values from the value space (a,b), either a is equal to b, denoted a = b, or a is not equal to b, denoted a != b;
  • there is no pair of instances (a, b) of values from the value space such that both a = b and a != b;
  • for every value a from the value space, a = a;
  • for any two instances (a, b) of values from the value space, a = b if and only if b = a;
  • for any three instances (a, b, c) of values from the value space, if a = b and b = c, then a = c.

On every datatype, the operation Equal is defined in terms of the equality property of the value space: for any values a, b drawn from the value space, Equal(a,b) is true if a = b, and false otherwise.

By definition, given value space A and value space B where A and B are not related by , for every pair of values a from A and b from B, a != b.

2.4.1.2 Order

[Definition:]  An order relation on a value space is a mathematical relation which imposes a total order on the members of the value space.

[Definition:]  A value space, and hence a datatype, is said to be ordered if there exists an order-relation defined for that value space.

order relations have the following rules:

  • for every pair (a, b) from the value space, either a < b or b < a, or a = b;
  • for every triple (a, b, c) from the value space, if a < b and b < c, then a < c.
2.4.1.3 Bounds

[Definition:]   A value space is bounded above if there exists a unique value U in the value space such that, for all values v in the value space, v <= U. [Definition:]   The value U is said to be an upper bound of the value space.

[Definition:]  A value space is bounded below if there exists a unique value L in the space such that, for all values v in the value space, L <= v. [Definition:]   The value L is then said to be a lower bound of the value space.

[Definition:]  A datatype is bounded if its value space has both an upper bound and a lower bound.

2.4.1.4 Cardinality

[Definition:]  Every value space has associated with it the concept of cardinality. Some value spaces are finite, some are countably infinite while still others are uncountably infinite. A datatype is said to have the cardinality of its value space.

It is sometimes useful to categorize value spaces (and hence, datatypes) as to their cardinality, there are two significant cases:

2.4.1.5 Numeric

[Definition:]  A datatype is said to be numeric if its values are conceptually quantities (in some mathematical number system).

[Definition:]  A datatype whose values are not numeric is said to be non-numeric.

2.4.2 Constraining or Non-fundamental facets

[Definition:]  A constraining facet is an optional property that can be applied to a datatype to constrain its value space.

Constraining the value space consequently constrains the lexical space. Adding constraining facets to a base type is described in Derivation by restriction (§5.1.1).

In this section we define all constraining facets that are available for use when defining derived datatypes.

2.4.2.1 length

[Definition:]  length is the number of units of length, where units of length varies depending on the base type. The value of length must be a nonNegativeInteger.

For datatypes derived from string, length is measured in units of [Unicode] code points. For datatypes derived from binary, length is measured in octets (8 bits) of binary data. For datatypes derived by list, length is measured in list items.

2.4.2.2 minLength

[Definition:]  minLength is the minimum number of units of length, where units of length varies depending on the base type. The value of minLength must be a nonNegativeInteger.

For datatypes derived from string, minLength is measured in units of [Unicode] code points. For datatypes derived from binary, minLength is measured in octets (8 bits) of binary data. For datatypes derived by list, length is measured in list items.

2.4.2.3 maxLength

[Definition:]  maxLength is the maximum number of units of length, where units of length varies depending on the base type. The value of maxLength must be a nonNegativeInteger.

For datatypes derived from string, maxLength is measured in units of [Unicode] code points. For datatypes derived from binary, maxLength is measured in octets (8 bits) of binary data. For datatypes derived by list, length is measured in list items.

2.4.2.4 pattern

[Definition:]   pattern is a constraint on the value space of a datatype which is achieved by constraining the lexical space to literals which match a specific pattern. The value of pattern must be a regular expression.

2.4.2.5 enumeration

[Definition:]   enumeration constrains the value space to a specified set of values.

enumeration does not impose an order relation on the value space it creates; the ordered property of the datatype involved remains that of the base type.

2.4.2.6 maxInclusive

[Definition:]   maxInclusive is the upper bound of the value space for a datatype with the ordered property. The value is inclusive in the sense that the value is itself included in the value space. The value of maxInclusive must be of the same type as the base type.

2.4.2.7 maxExclusive

[Definition:]   maxExclusive is the upper bound of the value space for a datatype with the ordered property. The value is exclusive in the sense that the value is itself excluded from the value space. The value of maxExclusive must be of the same type as the base type.

2.4.2.8 minInclusive

[Definition:]   minInclusive is the lower bound of the value space for a datatype with the ordered property. The value is inclusive in the sense that the value is itself included in the value space. The value of minInclusive must be of the same type as the base type.

2.4.2.9 minExclusive

[Definition:]   minExclusive is the lower bound of the value space for a datatype with the ordered property. The value is exclusive in the sense that the value is itself excluded from the value space for the datatype. The value of minExclusive must be of the same type as the base type.

2.4.2.10 precision

[Definition:]  precision is the maximum number of decimal digits in values of datatypes derived from decimal. The value of precision must be a positiveInteger.

2.4.2.11 scale

[Definition:]  scale is the maximum number of decimal digits in the fractional part of values of datatypes derived from decimal. The value of scale must be a nonNegativeInteger .

2.4.2.12 encoding

[Definition:]  encoding is the encoded form of the lexical space of datatypes derived from binary. The value of encoding must be one of {hex, base64}.

If the value of encoding is hex then each binary octect is encoded as a character tuple, consisting the two hexadecimal digits ([0-9a-fA-F]) representing the octet code. For example, "20" is the hex encoding for the US-ASCII space character.

If the value of encoding is base64 then the entire binary stream is encoding using the Base64 Content-Transfer-Encoding defined in Section 6.8 [RFC 2045].

2.4.2.13 duration

[Definition:]  duration is the duration of values for the datatype recurringDuration and datatypes derived from recurringDuration. The value of duration must be a timeDuration.

2.4.2.14 period

[Definition:]  period is the frequency of recurrence for values for the datatype recurringDuration and datatypes derived from recurringDuration. The value of period must be timeDuration.

2.5 Datatype dichotomies

It is useful to categorize the datatypes defined in this specification along various dimensions, forming a set of characterization dichotomies.

2.5.1 Atomic vs. list datatypes

The first distinction to be made is that between atomic and list datatypes.

  • [Definition:]  Atomic datatypes are those having values which are regarded by this specification as being indivisible.
  • [Definition:]  List datatypes are those having values which consist of a finite-length sequence of values of an atomic datatype.

For example, a single token which matches Nmtoken from [XML 1.0 Recommendation] could be the value of an atomic datatype (NMTOKEN); while a sequence of such tokens could be the value of a list datatype (NMTOKENS).

2.5.1.1 Atomic datatypes

atomic datatypes may be either primitive or derived. The value space of an atomic datatype is a set of "atomic" values, which for the purposes of this specification, are not further decomposable. The lexical space of an atomic datatype is a set of literals whose internal structure is specific to the datatype in question.

2.5.1.2 List datatypes

Several type systems (such as the one described in [ISO 11404]) treat list datatypes as special cases of the more general notions of aggregate or collection datatypes.

list datatypes are always derived. The value space of a list datatype is a set of finite-length sequences of atomic values. The lexical space of a list datatype is a set of literals whose internal structure is a whitespace separated sequence of literals of the atomic datatype of the items in the list (where whitespace matches S in [XML 1.0 Recommendation]).

Example
<simpleType name='sizes' base='decimal' derivedBy='list'/>
<cerealSizes xsi:type='sizes'> 8 10.5 12 </cerealSizes>

A list datatype can be derived from an atomic datatype whose lexical space allows whitespace. In such a case, regardless of the input, list items will be separated at whitespace boundaries.

Example
<simpleType name='listOfString' base='string' derivedBy='list'/>
<someElement xsi:type='listOfString'>
this is not list item 1
this is not list item 2
this is not list item 3
</someElement>
In the above example, the value of the someElement element is not a list of length 3; rather, it is a list of length 18.

When a datatype is derived from a list datatype, the following constraining facets may be used:

For each of the above facets, the unit of length is measured in number of list items.

NOTE: A datatype which is atomic in this specification need not be an "atomic" datatype in any programming language used to implement this specification. Likewise, a datatype which is a list in this specification need not be a "list" datatype in any programming language used to implement this specification.

2.5.2 Primitive vs. derived datatypes

Next, we distinquish between primitive and derived datatypes.

  • [Definition:]  Primitive datatypes are those that are not defined in terms of other datatypes; they exist ab initio.
  • [Definition:]  Derived datatypes are those that are defined in terms of other datatypes.

For example, a float is a well-defined mathematical concept that cannot be defined in terms of other datatypes while a date is a special case of the more general datatype recurringDuration.

The datatypes defined by this specification fall into both the primitive and derived categories. It is felt that a judiciously chosen set of primitive datatypes will serve the widest possible audience by providing a set of convenient datatypes that can be used as is, as well as providing a rich enough base from which the variety of datatypes needed by schema designers can be derived.

[Definition:]  Every derived datatype is defined in terms of an existing datatype, referred to as the base type. base types may be either primitive or derived.

In the example above, date is derived from the base type recurringDuration.

NOTE: A datatype which is primitive in this specification need not be a "primitive" datatype in any programming language used to implement this specification. Likewise, a datatype which is derived in this specification need not be a "derived" datatype in any programming language used to implement this specification.

2.5.3 Built-in vs. user-derived datatypes

Conceptually there is no difference between the built-in derived datatypes included in this specification and the user-derived datatypes which will be created by individual schema designers. The built-in derived datatypes are those which are believed to be so common that if they were not defined in this specification many schema designers would end up "reinventing" them. Furthermore, including these derived datatypes in this specification serves to demonstrate the mechanics and utility of the datatype generation facilities of this specification.

NOTE: A datatype which is built-in in this specification need not be a "built-in" datatype in any programming language used to implement this specification. Likewise, a datatype which is user-derived in this specification need not be a "user-derived" datatype in any programming language used to implement this specification.

3 Built-in datatypes

3.1 Namespace considerations

The built-in datatypes defined by this specification are designed so that systems other than the XML Schema definition language may use them. To facilitate such usage the built-in datatypes in this specification have the namespace URI:

This applies to both built-in primitive and built-in derived datatypes.

Each user-derived datatype is also associated with a unique namespace. However, user-derived datatypes do not come from the namespace defined by this specification; rather, they come from the namespace of the schema in which they are defined (see XML Representation of Schemas in [XML Schema Part 1: Structures]).

As described in more detail in XML representation of datatype definitions (§5.1), each user-derived datatype must be defined in terms of another datatype in one of two ways: 1) by assigning constraining facets which serve to restrict the value space of the user-derived datatype to a subset of the base type; 2) by creating a list datatype whose value space consists of finite-length sequences of values of the base type.

3.2 Primitive datatypes

The primitive datatypes defined by this specification are described below. For each datatype, the value space and lexical space are defined, all constraining facets which apply to the datatype are given and any datatypes derived from this the datatype are specified.

primitive datatypes can only be added by revisions to this specification.

3.2.1 string

[Definition:]  The string datatype represents character strings in XML. The value space of string is the set of finite-length sequences of UCS characters ([ISO 10646] and [Unicode]). A UCS character (or just character, for short) is an atomic unit of communication; it is not further specified except to note that every UCS character has a corresponding UCS code point, which is an integer. The order-relation of string is the lexicographic ordering by [Unicode] code point.

3.2.1.2 Derived datatypes

string has the following built-in  derived datatypes:

3.2.2 boolean

[Definition:]  boolean has the value space required to support the mathematical concept of binary-valued logic: {true, false}.

3.2.2.1 Lexical Representation

An instance of a datatype that is defined as boolean can have the following legal lexical values {true, 1, false, 0}, with '1' being the same as 'true' and '0' being the same as 'false'.

3.2.2.2 Constraining facets

boolean has the following constraining facets:

3.2.3 float

[Definition:]  float corresponds to the IEEE single-precision 32-bit floating point type [IEEE 754-1985]. The basic value space of float consists of the values m × 2^e, where m is an integer whose absolute value is less than 2^24, and e is an integer between -149 and 104, inclusive. In addition to the basic value space described above, the value space of float also contains the following special values: positive and negative zero, positive negative infinity and not-a-number. The order-relation on float is: x < y iff y - x is positive.

A literal in the lexical space representing a decimal number d maps to the normalized value in the value space of float that is closest to d; if d is exactly halfway between two such values then the even value is chosen. This is the best approximation of d [Clinger, WD (1990)] [Gay, DM (1990)], which is more accurate than the mapping required by [IEEE 754-1985].

3.2.3.1 Lexical representation

float values have a lexical representation consisting of a mantissa followed, optionally, by the character "E" or "e", followed by an exponent. The exponent must be an integer. The mantissa must be a decimal number. The representations for exponent and mantissa must follow the lexical rules for integer and decimal. If the "E" or "e" and the following exponent are omitted, an exponent value of 0 is assumed.

The special values positive and negative zero, positive and negative infinity and not-a-number have 0, -0, INF, -INF and NaN, respectively.

For example, -1E4, 1267.43233E12, 12.78e-2, 12 and INF are all legal literals for float.

3.2.3.2 Constraining facets

float has the following constraining facets:

3.2.4 double

[Definition:]  The double datatype corresponds to IEEE double-precision 64-bit floating point type [IEEE 754-1985]. The basic value space of double consists of the values m × 2^e, where m is an integer whose absolute value is less than 2^53, and e is an integer between -1075 and 970, inclusive. In addition to the basic value space described above, the value space of double also contains the following special values: positive and negative zero, positive negative infinity and not-a-number. The order-relation on double is: x < y iff y - x is positive.

A literal in the lexical space representing a decimal number d maps to the normalized value in the value space of double that is closest to d; if d is exactly halfway between two such values then the even value is chosen. This is the best approximation of d ([Clinger, WD (1990)], [Gay, DM (1990)]), which is more accurate than the mapping required by [IEEE 754-1985].

3.2.4.1 Lexical representation

double values have a lexical representation consisting of a mantissa followed, optionally, by the character "E" or "e", followed by an exponent. The exponent must be an integer. The mantissa must be a decimal number. The representations for exponent and mantissa must follow the lexical rules for integer and decimal. If the "E" or "e" and the following exponent are omitted, an exponent value of 0 is assumed.

The special values positive and negative zero, positive and negative infinity and not-a-number have 0, -0, INF, -INF and NaN, respectively.

For example, -1E4, 1267.43233E12, 12.78e-2, 12 and INF are all legal literals for double.

3.2.4.2 Constraining facets

double has the following constraining facets:

3.2.5 decimal

[Definition:]  decimal represents arbitrary precision decimal numbers. The value space of decimal consists of the values i × 10^n, where i and n are integers, with n being known as the scale of the value space. The order-relation on decimal is: x < y iff y - x is positive.

NOTE: The use of arbitrary precision decimal numbers, including all datatypes derived from decimal (e.g., integer) in this design impacts the implementation of schema processors in a number of places: checking maxLength constraints on strings, for example. It may impact interchange between XML schemas and programming languages, databases, etc.

Our design discussions did not reveal convincing evidence of undue burden because of arbitrary precision decimal numbers in this design, but we welcome further input from implementors.
3.2.5.1 Lexical representation

decimal has a lexical representation consisting of a finite-length sequence of decimal digits separated by a period as a decimal indicator, in accordance with the scale and precision facets, with an optional leading sign. If the sign is omitted, "+" is assumed. Leading and trailing zeroes are optional. If the fractional part is zero, the period and following zero(es) can be omitted. For example: -1.23, 12678967.543233, +100000.00.

3.2.5.3 Derived datatypes

decimal has the following built-in  derived datatypes:

3.2.6 timeDuration

[Definition:]   timeDuration represents a duration of time. The value space of timeDuration is the space of time durations as defined in § 5.5.3.2 of [ISO 8601]. The order-relation on timeDuration is: x < y iff y - x is positive.

3.2.6.1 Lexical Representation

A single lexical representation, conforming to a subset of the representations allowed by [ISO 8601], is allowed for timeDuration. This lexical representation is the [ISO 8601] extended format PnYn MnDTnH nMnS, where nY represents the number of years, nM the number of months, nD the number of days, 'T' is the date/time separator, nH the number of hours, nM the number of minutes and nS the number of seconds. The number of seconds can include decimal digits to arbitrary precision. An optional preceding minus sign ('-') is allowed, to indicate a negative duration. If the sign is omitted a positive duration is indicated. See also ISO 8601 Date and Time Formats (§D).

For example, to indicate a duration of 1 year, 2 months, 3 days, 10 hours, and 30 minutes, one would write: P1Y2M3DT10H30M.

Reduced precision and truncated representations of this format are allowed provided they conform to the following:

  • The lowest order items may be omitted. If omitted their value is assumed to be zero.
  • The lowest order item may have a decimal fraction.
  • If the number of years, months, days, hours, minutes, or seconds in any expression equals zero, the number and its corresponding designator may be omitted. However, at least one number and its designator must be present.
  • The designator 'T' shall be absent if all of the time items are absent. The designator 'P' must always be present.

For example, P1347Y, P1347M are P1Y2MT2H are all allowed; P0Y1347M and P0Y1347M0D are allowed. P-1347M is not allowed although -P1347M is allowed. P1Y2MT is not allowed.

3.2.6.2 Constraining facets

timeDuration has the following constraining facets:

3.2.7 recurringDuration

[Definition:]   recurringDuration represents a timeDuration that recurs with a specific timeDuration starting from a specific origin. The order-relation on timeDuration is: x < y iff y - x is positive.

Recurring duration has two constraining facets duration and period whose values must be specified when the datatype is defined. These facets specify the length of the duration and after what duration it recurs. The lexical format used to specify these facet values is the lexical format for timeDuration. A value of 0 for the facet period means that the duration does not recur i.e. there is but a single ocurrence. A value of 0 for the facet duration means that the duration is, in fact, a single instant of time.

Although the primary purpose of this datatype is to serve as a basetype from which the other date and time datatypes are generated, it can be used as a datatype on its own by specifying the values for duration and period when then datatype is defined. The value that appears in an instance document is the value of the origin when the recurrence begins.

Constraint: duration and period required for recurringDuration
It is an error for recurringDuration to be used directly in a schema. Only datatypes that are derived from recurringDuration by specifying a value for duration and period can be used in a schema.
3.2.7.1 Lexical Representation

A single lexical representation, which is a subset of the lexical representations allowed by [ISO 8601], is allowed for recurringDuration. This lexical representation is the [ISO 8601] extended format CCYY-MM-DDThh:mm:ss.sss where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day, preceded by an optional leading sign to indicate a negative number. If the sign is omitted, "+" is assumed. The letter "T" is the date/time separator and "hh", "mm", "ss.sss" represent hour, minute and second respectively. Additional digits can be used to increase the precision of fractional seconds if desired. To accommodate year values greater than 9999 additional digits can be added to the left of this representation.

This representation can be immediately followed by a "Z" to indicate Coordinated Universal Time. To indicate the time zone, i.e. the difference between the local time and Coordinated Universal Time, the difference immediately follows the time and consists of a sign, + or -, followed by hh:mm. See also ISO 8601 Date and Time Formats (§D).

The derived datatype timeInstant uses the same lexical representation. Other derived datatypes date, time, timePeriod and recurringDate use truncated versions of this lexical representation.

3.2.7.2 Constraining facets

recurringDuration has the following constraining facets:

3.2.7.3 Derived datatypes

recurringDuration has the following built-in  derived datatypes:

3.2.8 binary

[Definition:]  binary represents arbitrary binary data. The value space of binary is the set of finite-length sequences of binary octets.

Constraint: encoding required for binary
It is an error for binary to be used directly in a schema. Only datatypes that are derived from binary by minimally specifying a value for encoding can be used in a schema.
3.2.8.1 Constraining facets

binary has the following constraining facets:

Ed. Note: What does the pattern facet on binary really mean? Since pattern operates on the lexical space, one would have to give a regex for the base64 or hex that would result for a specific binary sequence that one wanted to constrain...this is not too far fetched for hex, but almost impossible for base64, isn't it?

3.2.9 uriReference

[Definition:]   uriReference represents a Uniform Resource Identifier (URI) Reference as defined in Section 4 of [RFC 2396]. A uriReference may be absolute or relative, and may have an optional fragment identifier.

[Definition:]   An absolute uriReference refers to a resource in a manner which is independent of the context in which the uriReference occurs.

[Definition:]   A relative uriReference refers to a resource by describing the difference within a hierarchy of resources between the context in which the relative uriReference occurs and the absolute uriReference of the resource.

3.2.9.1 Lexical representation

The lexical space of uriReference is the set of strings that match the URI-reference production in Section 4 of [RFC 2396].

3.2.9.2 Constraining facets

uriReference has the following constraining facets:

3.2.10 ID

[Definition:]  ID represents the ID attribute type from [XML 1.0 Recommendation]. The value space of ID is the set of all strings that match the NCName production in [Namespaces in XML] and have been used in an XML document. The lexical space of ID is the set of all strings that match the NCName production in [Namespaces in XML].

NOTE: The value space of ID is scoped to a specific instance document.

For compatibility (see Terminology (§1.4)) ID should be used only on attributes.

Constraint: ID Unique
An ID must not appear more than once in an XML document as a value of this type; i.e., ID values must uniquely identify the elements which bear them.

3.2.11 IDREF

[Definition:]  IDREF represents the IDREF attribute type from [XML 1.0 Recommendation]. The value space of IDREF is the set of all strings that match the NCName production in [Namespaces in XML] and have been used in an XML document as the value of an element or attribute of type ID. The lexical space of IDREF is the set of strings that match the NCName production in [Namespaces in XML].

NOTE: The value space of IDREF is scoped to a specific instance document.

For compatibility (see Terminology (§1.4)) this datatype should be used only on attributes.

Constraint: IDREF
An IDREF must match the value of an ID in the XML document in which it occurs.
3.2.11.2 Derived datatypes

IDREF has the following built-in  derived datatypes:

3.2.12 ENTITY

[Definition:]  ENTITY represents the ENTITY attribute type from [XML 1.0 Recommendation]. The value space of ENTITY is the set of all strings that match the NCName production in [Namespaces in XML] and have been declared as an unparsed entity in a document type definition. The lexical space of ENTITY is the set of all strings that match the NCName production in [Namespaces in XML].

NOTE: The value space of ENTITY is scoped to a specific instance document.
Constraint: ENTITY declared
ENTITY values must match an unparsed entity name that is declared in the schema.

For compatibility (see Terminology (§1.4)) ENTITY should be used only on attributes.

3.2.12.2 Derived datatypes

ENTITY has the following built-in  derived datatypes:

3.2.13 NOTATION

[Definition:]  NOTATION represents the NOTATION attribute type from [XML 1.0 Recommendation]. The value space of NOTATION is the set of all notations declared in a schema. The lexical space of NOTATION is the set of all strings that match the NCName production in [Namespaces in XML].

NOTE: The value space of NOTATION is scoped to a specific instance document.
Constraint: NOTATION declared
NOTATION values must match a notation name that is declared in the schema.

For compatibility (see Terminology (§1.4)) NOTATION should be used only on attributes.

3.2.14 QName

[Definition:]  QName represents XML qualified names. The value space of QName is the set of tuples {namespace name, local part}, where namespace name is a uriReference and local part is an NCName. The lexical space of QName is the set of strings that match the QName production of [Namespaces in XML].

3.3 Derived datatypes

This section gives conceptual definitions for all built-in derived datatypes defined by this specification. The XML Representation used to define derived datatypes (whether built-in or user-derived) is given in section XML representation of datatype definitions (§5.1) and the complete definitions of the built-in derived datatypes are provided in Appendix Schema for Datatype Definitions (normative) (§A).

3.3.1 language

[Definition:]  language represents natural language identifiers as defined by [RFC 1766]. The value space of language is the set of all strings that match the LanguageID production in [XML 1.0 Recommendation]. The lexical space of language is the set of all strings that match the LanguageID production in [XML 1.0 Recommendation]. The base type of language is string.

3.3.2 IDREFS

[Definition:]  IDREFS represents the IDREFS attribute type from [XML 1.0 Recommendation]. The value space of IDREFS is the set of finite-length sequences of IDREFs that have been used in an XML document. The lexical space of IDREFS is the set of whitespace separated tokens, each of which is in the lexical space of IDREF. The base type of IDREFS is IDREF.

NOTE: The value space of IDREFS is scoped to a specific instance document.

For compatibility (see Terminology (§1.4)) IDREFS should be used only on attributes.

3.3.2.1 Constraining facets

IDREFS has the following constraining facets:

3.3.3 ENTITIES

[Definition:]  ENTITIES represents the ENTITIES attribute type from [XML 1.0 Recommendation]. The value space of ENTITIES is the set of finite-length sequences of ENTITYs that have been declared as unparsed entities in a document type definition. The lexical space of ENTITIES is the set of whitespace separated tokens, each of which is in the lexical space of NMTOKEN. The base type of ENTITIES is ENTITY.

NOTE: The value space of ENTITIES is scoped to a specific instance document.

For compatibility (see Terminology (§1.4)) ENTITIES should be used only on attributes.

3.3.3.1 Constraining facets

ENTITIES has the following constraining facets:

3.3.4 NMTOKEN

[Definition:]  NMTOKEN represents the NMTOKEN attribute type from [XML 1.0 Recommendation]. The value space of NMTOKEN is the set of tokens that match the Nmtoken production in [XML 1.0 Recommendation]. The lexical space of NMTOKEN is the set of strings that match the Nmtoken production in [XML 1.0 Recommendation]. The base type of NMTOKEN is string.

For compatibility (see Terminology (§1.4)) NMTOKEN should be used only on attributes.

3.3.4.2 Derived datatypes

NMTOKEN has the following built-in  derived datatypes:

3.3.5 NMTOKENS

[Definition:]  NMTOKENS represents the NMTOKENS attribute type from [XML 1.0 Recommendation]. The value space of NMTOKENS is the set of fininte-length sequences of NMTOKENs. The lexical space of NMTOKENS is the set of whitespace separated tokens, each of which is in the lexical space of NMTOKEN. The base type of NMTOKENS is NMTOKEN.

For compatibility (see Terminology (§1.4)) NMTOKENS should be used only on attributes.

3.3.5.1 Constraining facets

NMTOKENS has the following constraining facets:

3.3.6 Name

[Definition:]  Name represents XML Names. The value space of Name the set of all strings which match the Name production of [XML 1.0 Recommendation]. The lexical space of Name is the set of all strings which match the Name production of [XML 1.0 Recommendation]. The base type of Name is string.

3.3.6.2 Derived datatypes

Name has the following built-in  derived datatypes:

3.3.7 NCName

[Definition:]  NCName represents XML "non-colonized" Names. The value space of NCName is the set of all strings which match the NCName production of [Namespaces in XML]. The lexical space of NCName is the set of all strings which match the NCName production of [Namespaces in XML]. The base type of NCName is Name.

3.3.8 integer

[Definition:]  integer is derived from decimal by fixing the value of scale to be 0. This results in the standard mathematical concept of the integer numbers. The value space of integer is the infinite set {...,-2,-1,0,1,2,...}. The base type of integer is decimal.

3.3.8.1 Lexical representation

integer has a lexical consisting of a finite-length sequence of decimal digits with an optional leading sign. If the sign is omitted, "+" is assumed. For example: -1, 0, 12678967543233, +100000.

3.3.8.3 Derived datatypes

integer has the following built-in  derived datatypes:

3.3.9 nonPositiveInteger

[Definition:]   nonPositiveInteger is derived from integer by fixing the value of maxInclusive to be 0. This results in the standard mathematical concept of the non-positive integers. The value space of nonPositiveInteger is the infinite set {...,-2,-1,0}. The base type of nonPositiveInteger is integer.

3.3.9.1 Lexical representation

nonPositiveInteger has a lexical representation consisting of a negative sign ("-") followed by a finite-length sequence of decimal digits. If the sequence of digits consists of all zeros then the sign is optional. For example: -1, 0, -12678967543233, -100000.

3.3.9.2 Constraining facets

nonPositiveInteger has the following constraining facets:

3.3.9.3 Derived datatypes

nonPositiveInteger has the following built-in  derived datatypes:

3.3.10 negativeInteger

[Definition:]   negativeInteger is derived from nonPositiveInteger by fixing the value of maxInclusive to be -1. This results in the standard mathematical concept of the negative integers. The value space of negativeInteger is the infinite set {...,-2,-1}. The base type of negativeInteger is nonPositiveInteger.

3.3.10.1 Lexical representation

negativeInteger has a lexical representation consisting of a negative sign ("-") followed by a finite-length sequence of decimal digits. For example: -1, -12678967543233, -100000.

3.3.10.2 Constraining facets

negativeInteger has the following constraining facets:

3.3.11 long

[Definition:]  long is derived from integer by fixing the values of maxInclusive to be 9223372036854775807 and minInclusive to be -9223372036854775808. The base type of long is integer.

3.3.11.1 Lexical representation

long has a lexical representation consisting of an optional sign followed by a finite-length sequence of decimal digits. If the sign is omitted, "+" is assumed. For example: -1, 0, 12678967543233, +100000.

3.3.11.3 Derived datatypes

long has the following built-in  derived datatypes:

3.3.12 int

[Definition:]  int is derived from long by fixing the values of maxInclusive to be 2147483647 and minInclusive to be -2147483648. The base type of int is long.

3.3.12.1 Lexical representation

int has a lexical representation consisting of an optional sign followed by a finite-length sequence of decimal digits. If the sign is omitted, "+" is assumed. For example: -1, 0, 126789675, +100000.

3.3.12.3 Derived datatypes

int has the following built-in  derived datatypes:

3.3.13 short

[Definition:]  short is derived from int by fixing the values of maxInclusive to be 32767 and minInclusive to be -32768. The base type of short is int.

3.3.13.1 Lexical representation

short has a lexical representation consisting of an optional sign followed by a finite-length sequence of decimal digits. If the sign is omitted, "+" is assumed. For example: -1, 0, 12678, +10000.

3.3.13.3 Derived datatypes

short has the following built-in  derived datatypes:

3.3.14 byte

[Definition:]  byte is derived from short by fixing the values of maxInclusive to be 127 and minInclusive to be -128. The base type of byte is short.

3.3.14.1 Lexical representation

byte has a lexical representation consisting of an optional sign followed by a finite-length sequence of decimal digits. If the sign is omitted, "+" is assumed. For example: -1, 0, 126, +100.

3.3.15 nonNegativeInteger

[Definition:]   nonNegativeInteger is derived from integer by fixing the value of minInclusive to be 0. This results in is the standard mathematical concept of the non-negative integers. The value space of nonNegativeInteger is the infinite set {0,1,2,...}. The base type of nonNegativeInteger is integer.

3.3.15.1 Lexical representation

nonNegativeInteger has a lexical representation consisting of an optional sign followed by a finite-length sequence of decimal digits. If the sign is omitted, "+" is assumed. For example: 1, 0, 12678967543233, +100000.

3.3.15.2 Constraining facets

nonNegativeInteger has the following constraining facets:

3.3.15.3 Derived datatypes

nonNegativeInteger has the following built-in  derived datatypes:

3.3.16 unsignedLong

[Definition:]   unsignedLong is derived from nonNegativeInteger by fixing the values of maxInclusive to be 18446744073709551615. The base type of unsignedLong is nonNegativeInteger.

3.3.16.1 Lexical representation

unsignedLong has a lexical representation consisting of a finite-length sequence of decimal digits. For example: 0, 12678967543233, 100000.

3.3.16.2 Constraining facets

unsignedLong has the following constraining facets:

3.3.16.3 Derived datatypes

unsignedLong has the following built-in  derived datatypes:

3.3.17 unsignedInt

[Definition:]   unsignedInt is derived from unsignedLong by fixing the values of maxInclusive to be 4294967295. The base type of unsignedInt is unsignedLong.

3.3.17.1 Lexical representation

unsignedInt has a lexical representation consisting of a finite-length sequence of decimal digits. For example: 0, 1267896754, 100000.

3.3.17.2 Constraining facets

unsignedInt has the following constraining facets:

3.3.17.3 Derived datatypes

unsignedInt has the following built-in  derived datatypes:

3.3.18 unsignedShort

[Definition:]   unsignedShort is derived from unsignedInt by fixing the value maxInclusive to be 65535. The base type of unsignedShort is unsignedInt.

3.3.18.1 Lexical representation

unsignedShort has a lexical representation consisting of a finite-length sequence of decimal digits. For example: 0, 12678, 10000.

3.3.18.2 Constraining facets

unsignedShort has the following constraining facets:

3.3.18.3 Derived datatypes

unsignedShort has the following built-in  derived datatypes:

3.3.19 unsignedByte

[Definition:]   unsignedByte is derived from unsignedShort by fixing the value maxInclusive to be 255. The base type of unsignedByte is unsignedShort.

3.3.19.1 Lexical representation

unsignedByte has a lexical representation consisting of a finite-length sequence of decimal digits. For example: 0, 126, 100.

3.3.19.2 Constraining facets

unsignedByte has the following constraining facets:

3.3.20 positiveInteger

[Definition:]   positiveInteger is derived from nonNegativeInteger by fixing the value of minInclusive to be 1. This results in the standard mathematical concept of the positive integer numbers. The value space of positiveInteger is the infinite set {1,2,...}. The base type of positiveInteger is nonNegativeInteger.

3.3.20.1 Lexical representation

positiveInteger has a lexical representation consisting of an optional positive sign ("+") followed by a finite-length sequence of decimal digits. For example: 1, 12678967543233, +100000.

3.3.20.2 Constraining facets

positiveInteger has the following constraining facets:

3.3.21 timeInstant

[Definition:]   timeInstant represents a specific instant of time. The value space of timeInstant is the space of Combinations of date and time of day values as defined in § 5.4 of [ISO 8601]. The base type of timeInstant is recurringDuration. timeInstant is generated from recurringDuration by setting the value of the duration facet equal to "P0Y" and the value of the period facet equal to "P0Y" (no recurrence).

3.3.21.1 Lexical Representation

A single lexical representation, which is a subset of the lexical representations allowed by [ISO 8601], and is the same lexical representation as its basetype recurringDuration is allowed for timeInstant.

For example, to indicate 1:20 pm on May the 31st, 1999 for Eastern Standard Time which is 5 hours behind Coordinated Universal Time, one would write: 1999-05-31T13:20:00-05:00.

3.3.21.2 Constraining facets

timeInstant has the following constraining facets:

3.3.22 time

[Definition:]  time represents an instant of time that recurs every day. The value space of time is the space of time of day values as defined in § 5.3 of [ISO 8601]. The base type of time is recurringDuration. date is generated from recurringDuration by setting the value of the duration facet equal to "P0Y" and the value of the period facet equal to "PY24H" (24 hours).

3.3.22.1 Lexical Representation

The lexical representation for time is the left truncated lexical representation for timeInstant: hh:mm:ss.sss with optional following time zone indicator. For example, to indicate 1:20 pm for Eastern Standard Time which is 5 hours behind Coordinated Universal Time, one would write: 13:20:00-05:00. See also ISO 8601 Date and Time Formats (§D).

3.3.22.2 Constraining facets

time has the following constraining facets: