How XML Schema Validates ISO 8601 DateTime Strings

XML Schema (XSD) validates ISO 8601 extended formatted timestamps primarily through its built-in primitive data type, xs:dateTime. This article explains the lexical rules that XSD parsers enforce to validate these date and time representations, covering the required components, calendar constraints, timezone offsets, and custom validation facets available for granular control.

The Lexical Format of xs:dateTime

The xs:dateTime data type enforces a strict subset of the ISO 8601 extended format. The required lexical representation follows the pattern:

[-]CCYY-MM-DDThh:mm:ss[.sss][Z|(+|-)hh:mm]

An XML Schema validator decomposes this string into specific components and evaluates each against predetermined rules:

Calendar and Logical Constraint Checking

Beyond pattern matching, an XML Schema processor verifies the logical validity of the date:

  1. Days per Month: The validator enforces the exact number of days in each month (e.g., April must not exceed 30 days).
  2. Leap Years: February 29th is validated against the Gregorian leap year calculation rules (divisible by 4, except for century years not divisible by 400).
  3. Leap Seconds: The second field accepts values up to 60 in schemas supporting leap seconds, though standard operations normalize or limit values to 59.999....

Timezone Processing

When a timezone is provided, the validator checks that the hour offset does not exceed 14:00 (positive or negative). In schema-aware operations, timestamps with timezones are converted to a normalized UTC timeline, allowing the processor to compare relative chronological ordering accurately. If a timestamp lacks a timezone, it is treated as an undetermined local time.

Applying Custom Facets

To further restrict xs:dateTime values beyond standard ISO 8601 validation, developers can apply XSD constraining facets: