Skip to content

XSD String

How XSD string data types (xs:string, normalizedString, token) work in XML schemas, including their differences in handling whitespace, line breaks, and formatting.

String data types are used to represent characters in the XML documents.

String Data Type

The string data type (<xs:string>) can contain characters, line feeds, carriage returns, and tab characters. Note that multiple spaces or tabs are preserved while displaying.

For example:

<xs:element name="person" type="xs:string"/>

and elements in your XML document could be:

<person>Tom</person>
<person>Tom Nolan</person>
<person>Tom    Nolan</person>

NormalizedString Data Type

The normalizedString data type is derived from the String data type.

The normalizedString data type also contains characters, but the XML processor will remove line feeds, carriage returns, and tab characters.

For example:

<xs:element name="person" type="xs:normalizedString"/>

and elements in your XML document could be:

<person>Tom</person>
<person>Tom Nolan</person>
<person>Tom    Nolan</person>

Token Data Type

The token data type (<xs:token>) is also derived from the String data type (<xs:string>).

The token data type also contains characters, but the XML processor will remove line feeds, carriage returns, tabs, leading and trailing spaces, and multiple spaces.

For example:

<xs:element name="person" type="xs:token"/>

and elements in your XML document could be:

<person>Tom</person>
<person>Tom Nolan</person>
<person>Tom    Nolan</person>

All String Data Types

Following is the list of commonly used data types which are derived from <xs:string> data type.

Name Description
ENTITIES
ENTITY
ID A string that represents the ID attribute in XML (only used with schema attributes)
IDREF A string that represents the IDREF attribute in XML (only used with schema attributes)
IDREFS
language A string that contains a valid language id
Name A string that contains a valid XML name
NCName
NMTOKEN A string that represents the NMTOKEN attribute in XML (only used with schema attributes)
NMTOKENS
normalizedString A string that does not contain line feeds, carriage returns, or tabs
QName
string A string
token A string that does not contain line feeds, carriage returns, tabs, leading or trailing spaces, or multiple spaces

Restrictions on String Data Type

Following types of restrictions can be used with String data types:

  • enumeration
  • length
  • maxLength
  • minLength
  • pattern
  • whiteSpace

See XSD Restrictions chapter to learn more.

Navigation