XML Data Types Reference
The World Wide Web Consortium (W3C) XML Schema Part 2: DataTypes is the specification for defining data types used in XML Schemas. This specification defines built-in primitive data types, derived data types, and facets.
The following diagram shows the type hierarchy.

Primitive XML Data Types
The following table lists primitive XML schema data types, facets that can be applied to the data type, and a description of the data type.
Facets can only appear once in a type definition except for enumeration and pattern facets. Enumeration and pattern facets can have multiple entries and are grouped together.
| Data Type | Facets | Description |
|---|---|---|
| string | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents character strings. |
| boolean | pattern, whiteSpace | Represents Boolean values, which are either true or false. |
| decimal | enumeration, pattern, totalDigits, fractionDigits, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents arbitrary precision numbers. |
| float | pattern, enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents single-precision 32-bit floating-point numbers. |
| double | pattern, enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents double-precision 64-bit floating-point numbers. |
| duration | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents a duration of time.
The pattern for duration is |
| dateTime | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents a specific instance of time.
The pattern for dateTime is This representation may be immediately followed by a "Z" to indicate Coordinated Universal Time (UTC) or to indicate the time zone. For example, the difference between the local time and Coordinated Universal Time, immediately followed by a sign, + or -, followed by the difference from UTC represented as |
| time | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents an instance of time that recurs every day.
The pattern for time is |
| date | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents a calendar date.
The pattern for date is |
| gYearMonth | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents a specific Gregorian month in a specific Gregorian year. A set of one-month long, nonperiodic instances.
The pattern for gYearMonth is |
| gYear | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents a Gregorian year. A set of one-year long, nonperiodic instances.
The pattern for gYear is |
| gMonthDay | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents a specific Gregorian date that recurs, specifically a day of the year such as the third of May. A gMonthDay is the set of calendar dates. Specifically, it is a set of one-day long, annually periodic instances.
The pattern for gMonthDay is |
| gDay | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents a Gregorian day that recurs, specifically a day of the month such as the fifth day of the month. A gDay is the space of a set of calendar dates. Specifically, it is a set of one-day long, monthly periodic instances.
The pattern for gDay is |
| gMonth | enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace | Represents a Gregorian month that recurs every year. A gMonth is the space of a set of calendar months. Specifically, it is a set of one-month long, yearly periodic instances.
The pattern for gMonth is |
| hexBinary | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents arbitrary hex-encoded binary data. A hexBinary is the set of finite-length sequences of binary octets. Each binary octet is encoded as a character tuple, consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code. |
| base64Binary | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents Base64-encoded arbitrary binary data. A base64Binary is the set of finite-length sequences of binary octets. |
| anyURI | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents a URI as defined by RFC 2396. An anyURI value can be absolute or relative, and may have an optional fragment identifier. |
| QName | length, enumeration, pattern, maxLength, minLength, whiteSpace | Represents a qualified name. A qualified name is composed of a prefix and a local name separated by a colon. Both the prefix and local names must be an NCName. The prefix must be associated with a namespace URI reference, using a namespace declaration. |
| NOTATION | length, enumeration, pattern, maxLength, minLength, whiteSpace | Represents a NOTATION attribute type. A set of QNames. |
Derived XML Data Types
The following table lists derived XML schema data types, facets that can be applied to the derived data type, and a description of the derived data type.
| Data Type | Facets | Description |
|---|---|---|
| normalizedString | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents white space normalized strings. This data type is derived from string. |
| token | enumeration, pattern, length, minLength, maxLength, whiteSpace | Represents tokenized strings. This data type is derived from normalizedString. |
| language | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents natural language identifiers (defined by RFC 1766). This data type is derived from token. |
| IDREFS | length, maxLength, minLength, enumeration, whiteSpace | Represents the IDREFS attribute type. Contains a set of values of type IDREF. |
| ENTITIES | length, maxLength, minLength, enumeration, whiteSpace | Represents the ENTITIES attribute type. Contains a set of values of type ENTITY. |
| NMTOKEN | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents the NMTOKEN attribute type. An NMTOKEN is set of name characters (letters, digits, and other characters) in any combination. Unlike Name and NCName, NMTOKEN has no restrictions on the starting character. This data type is derived from token. |
| NMTOKENS | length, maxLength, minLength, enumeration, whiteSpace | Represents the NMTOKENS attribute type. Contains a set of values of type NMTOKEN. |
| Name | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents names in XML. A Name is a token that begins with a letter, underscore, or colon and continues with name characters (letters, digits, and other characters). This data type is derived from token. |
| NCName | length, pattern, maxLength, minLength, enumeration, whiteSpace | Represents noncolonized names. This data type is the same as Name, except it cannot begin with a colon. This data type is derived from Name. |
| ID | length, enumeration, pattern, maxLength, minLength, whiteSpace | Represents the ID attribute type defined in the XML 1.0 Recommendation. The ID must be a no-colon-name (NCName) and must be unique within an XML document. This data type is derived from NCName. |
| IDREF | length, enumeration, pattern, maxLength, minLength, whiteSpace | Represents a reference to an element that has an ID attribute that matches the specified ID. An IDREF must be an NCName and must be a value of an element or attribute of type ID within the XML document. This data type is derived from NCName. |
| ENTITY | length, enumeration, pattern, maxLength, minLength, whiteSpace | Represents the ENTITY attribute type in XML 1.0 Recommendation. This is a reference to an unparsed entity with a name that matches the specified name. An ENTITY must be an NCName and must be declared in the schema as an unparsed entity name. This data type is derived from NCName. |
| integer | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents a sequence of decimal digits with an optional leading sign (+ or -). This data type is derived from decimal. |
| nonPositiveInteger | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer that is less than or equal to zero. A nonPositiveInteger consists of a negative sign (-) and sequence of decimal digits. This data type is derived from integer. |
| negativeInteger | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer that is less than zero. Consists of a negative sign (-) and sequence of decimal digits. This data type is derived from nonPositiveInteger. |
| long | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer with a minimum value of -9223372036854775808 and maximum of 9223372036854775807. This data type is derived from integer. |
| int | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer with a minimum value of -2147483648 and maximum of 2147483647. This data type is derived from long. |
| short | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer with a minimum value of -32768 and maximum of 32767. This data type is derived from int. |
| byte | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer with a minimum value of -128 and maximum of 127. This data type is derived from short. |
| nonNegativeInteger | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer that is greater than or equal to zero. This data type is derived from integer. |
| unsignedLong | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer with a minimum of zero and maximum of 18446744073709551615. This data type is derived from nonNegativeInteger. |
| unsignedInt | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer with a minimum of zero and maximum of 4294967295. This data type is derived from unsignedLong. |
| unsignedShort | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer with a minimum of zero and maximum of 65535. This data type is derived from unsignedInt. |
| unsignedByte | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer with a minimum of zero and maximum of 255. This data type is derived from unsignedShort. |
| positiveInteger | enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace | Represents an integer that is greater than zero. This data type is derived from nonNegativeInteger. |
Data Type Facets
Simple types (both built-in and derived) have facets. A facet is a single defining aspect that helps determine the set of values for a simple type. For example, length, minInclusive, and maxInclusive are common facets for the built-in data types. All of the facets for a simple type define the set of legal values for that simple type.
A facet is defined as an element. Each facet element has a fixed attribute that is a Boolean value. When a simple type is defined, you can prevent derivatives of that type from modifying the value of specified facets. To prevent modification of a facet, add the fixed attribute to the facet and set its value to true.
Facets can only appear once in a type definition except for enumeration and pattern facets. Enumeration and pattern facets can have multiple entries and are grouped together.
Example
The following example shows a simple type with the fixed attribute set to true which prevents the length from having a value other than 7.
<xs:simpleType name="Postcode"> <xs:restriction base="xs:string"> <xs:length value="7" fixed="true"/> </xs:restriction> </xs:simpleType>
List of Constraining Facets
The constraining facets (facets that can be used to constrain the values of simple types), their descriptions, and the built-in data types that they apply to, are listed below.
- enumeration
- Specified set of values. This constrains a data type to the specified values. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-enumeration.
- fractionDigits
- Value with specific maximum number of decimal digits in the fractional part. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-fractionDigits.
- length
- Number of units of length. Units of length depend on the data type. This value must be a nonNegativeInteger. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-length.
- maxExclusive
- Upper bound value (all values are less than this value). This value must be the same data type as the inherited data type. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-maxExclusive.
- maxInclusive
- Maximum value. This value must be the same data type as the inherited data type. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-maxInclusive.
- maxLength
- Maximum number of units of length. Units of length depend on the data type. This value must be a nonNegativeInteger. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-maxLength.
- minExclusive
- Lower bound value (all values are greater than this value). This value must be the same data type as the inherited data type. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-minExclusive.
- minInclusive
- Minimum value. This value must be the same data type as the inherited data type. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-minInclusive.
- minLength
- Minimum number of units of length. Units of length depend on the data type. This value must be a nonNegativeInteger. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-minLength.
- pattern
- Specific pattern that the data type's values must match. This constrains the data type to literals that match the specified pattern. The pattern value must be a regular expression. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-pattern.
- totalDigits
- Value with specific maximum number of decimal digits. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-totalDigits.
- whiteSpace
- Value must be one of preserve, replace, or collapse. The whiteSpace facet cannot be changed for most numeric data types. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#element-whiteSpace.
preserve No normalization is performed; the value is not changed for element content as required by the W3C XML 1.0 Recommendation. replace All occurrences of #x9 (tab), #xA (line feed) and #xD (carriage return) are replaced with #x20 (space). collapse After the processing implied by replace, contiguous sequences of #x20s are collapsed to a single #x20, and leading and trailing #x20s are removed.
浙公网安备 33010602011771号