XSD String Data Types

For the values containing the character strings, the string data types are used.

XSD Example:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
<xs:element name="note">
 
<xs:complextype>
  <xs:sequence>
    <xs:element name="to" type="xs:string"></xs:element>
    <xs:element name="from" type="xs:string"></xs:element>
    <xs:element name="heading" type="xs:string"></xs:element>
    <xs:element name="body" type="xs:string"></xs:element>
  </xs:sequence>
</xs:complextype>
 
</xs:element>
</xs:schema>

String Data Type:

The characters, line feeds, carriage returns, and tab characters are included in the string data type. On using the string data type, the XML processor will not modify the value.

Example: String declaration in a schema:

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

An element in a document:

<student>Tony Jonas</student>

Or:

<student> Tony Jonas </student>

NormalizedString Data Type:

Derived from the String data type, the normalizedString data type also contains characters, but here, the line feeds, carriage returns, and tab characters will be removed by the XML.

Example: NormalizedString declaration in a schema:

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

An element in a document:

<student>Tony Jonas</student>

Or:

<student> Tony Jonas </student>

Explanation:

In the above example, the tabs will be replaced with spaces by the XML processor.

Token Data Type:

Derived from the String data type, the token data type also contains characters, but here, the line feeds, carriage returns, tabs, leading and trailing spaces, and multiple spaces will be removed by the XML processor.

Example: Token declaration in a schema:

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

An element in a document:

<student>Tony Jonas</student>

Or:

<student> Tony Jonas </student>

Explanation:

In the above example, the tabs will be removed by the XML processor.

String Data Types:

Except for string itself, all the data types mentioned below are derived from the String data type.

Name Uses
ENTITIES
ENTITY
ID Used to specify a string that represents the ID attribute in XML. Only used with schema attributes.
IDREF Used to specify a string that represents the IDREF attribute in XML. Only used with schema attributes.
IDREFS
language Used to specify a string that contains a valid language id.
Name Used to specify a string that contains a valid XML name.
NCName
NMTOKEN Used to specify a string that represents the NMTOKEN attribute in XML. Only used with schema attributes.
NMTOKENS
normalizedString Used to specify a string that does not contain line feeds, carriage returns, or tabs.
QName
string Used to specify a string.
token Used to specify a string that does not contain line feeds, carriage returns, tabs, leading or trailing spaces, or multiple spaces.

Restrictions on String Data Types:

Restrictions used with String data types:

  • enumeration
  • length
  • maxLength
  • minLength
  • pattern (NMTOKENS, IDREFS, and ENTITIES cannot use this constraint)
  • whiteSpace
Please Share