Table of Contents

XML Schema

This is a cheat sheet for the XML Schema language. It is a follow up to the XML Cheat Sheet and summarizes this XML Schema Tutorial. There is also a DTD Cheat Sheet.

For reference this is the XML Schema homepage including specifications and a primer.

Simple Types

Facets / Restrictions

Restriction Description
enumeration Defines a list of acceptable values
fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero
length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero
maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value)
maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero
minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value)
minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero
pattern Defines the exact sequence of characters that are acceptable
totalDigits Specifies the exact number of digits allowed. Must be greater than zero
whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled

Complex Elements

Element Indicators

* An Attribute group is similar for example.

<xs:attributeGroup name="personattrgroup">
  <xs:attribute name="firstname" type="xs:string"/>
  <xs:attribute name="lastname" type="xs:string"/>
</xs:attributeGroup>

A reference to the attribute group in a complex type would look like :

 <xs:attributeGroup ref="personattrgroup"/> 

Data Types

String Data Types

Date Data Types

Type Description
date Defines a date value (“YYYY-MM-DD”)
dateTime Defines a date and time value (“YYYY-MM-DDThh:mm:ss”)
duration Defines a time interval ([-]PnYnMnDTnHnMnS)
gDay Defines a part of a date - the day (DD)
gMonth Defines a part of a date - the month (MM)
gMonthDay Defines a part of a date - the month and day (MM-DD)
gYear Defines a part of a date - the year (YYYY)
gYearMonth Defines a part of a date - the year and month (YYYY-MM)
time Defines a time value (“hh:mm:ss”)

Numeric Data types

Name Description
byte A signed 8-bit integer
decimal A decimal value
int A signed 32-bit integer
integer An integer value
long A signed 64-bit integer
negativeInteger An integer containing only negative values ( .., -2, -1.)
nonNegativeInteger An integer containing only non-negative values (0, 1, 2, ..)
nonPositiveInteger An integer containing only non-positive values (.., -2, -1, 0)
positiveInteger An integer containing only positive values (1, 2, ..)
short A signed 16-bit integer
unsignedLong An unsigned 64-bit integer
unsignedInt An unsigned 32-bit integer
unsignedShort An unsigned 16-bit integer
unsignedByte An unsigned 8-bit integer

Other Data Types