XML technologies / XML Schema / Data type reference / xs:token

(Excerpt from “XML Schema” by Eric van der Vlist)

Strings with whitespace replacement and collapsing

Derived from: xs:normalizedString

Primitive type: xs:string

Known subtypes: xs:language, xs:NMTOKEN, xs:Name

Facets: xs:enumeration, xs:length, xs:maxLength, xs:minLength, xs:pattern, xs:whiteSpace

Definition

<xs:simpleType name="token" id="token">
    <xs:restriction base="xs:normalizedString">
        <xs:whiteSpace value="collapse"/>
    </xs:restriction>
</xs:simpleType>

Description

The lexical and value spaces of xs:token consist of strings after whitespace replacement: each occurrence of #x9 (tab), #xA (line feed) and #xD (carriage return) is replaced by #x20 (space), then whitespace is collapsed: consecutive spaces become one and leading and trailing spaces are removed.

Put simply, xs:token is the most suitable data type for strings where whitespace is insignificant.

Restrictions

The name xs:token is misleading because whitespace is allowed within xs:token . Instead, xs:NMTOKEN corresponds to what is usually called a token.

Example

The element:

<title lang="de">
    Auf den
    Hund gekommen
</title>

is valid for xs:token, and its value is the string “Auf den Hund gekommen”: all whitespace has been replaced by spaces, leading and trailing spaces removed, and consecutive spaces collapsed to one.

   

 

 

 

back to top