Skip to main content

XSD String

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>
note

The XML processor will not modify the value if you use the string data type.

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>
note

In the example above the XML processor will replace the tabs with spaces.

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>
note

In the example above the XML processor will remove the tabs.

All String Data Types

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

NameDescription
ENTITIES
ENTITY
IDA string that represents the ID attribute in XML (only used with schema attributes)
IDREFA string that represents the IDREF attribute in XML (only used with schema attributes)
IDREFS
languageA string that contains a valid language id
NameA string that contains a valid XML name
NCName
NMTOKENA string that represents the NMTOKEN attribute in XML (only used with schema attributes)
NMTOKENS
normalizedStringA string that does not contain line feeds, carriage returns, or tabs
QName
stringA string
tokenA 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.