Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML Schema string data type


May 28, 2021 XML Schema


Table of contents


XSD string data type

This section introduces you to the string data types of XML Schema.


String data types are used for values that can contain strings.


String Data Type

String data types can contain characters, line breaks, carriage returns, and tabs.

Here's an example of a string declaration in a scheme:

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

The elements in the document should look something like this:

<customer>John Smith</customer>

Or something like this:

<customer>       John Smith     </customer>

Note: If you use string data types, the XML processor does not change the values in them.


Normalized String Data Type

The normalized string data type originates from the string data type.

The normalized string data type can also contain characters, but the XML processor removes lines, carriage returns, and tabs.

Here's an example of a string data type that is normalized in a schema:

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

The elements in the document should look something like this:

<customer>John Smith</customer>

Or something like this:

<customer>     John Smith     </customer>

Note: In the example above, the XML processor replaces all tabs with spaces.


Token Data Type

Token data types also originate from string data types.

Token data types can also contain characters, but the XML processor removes line breaks, carriage returns, tabs, spaces at the beginning and end, and (continuous) spaces.

Here's an example of a token declaration in schema:

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

The elements in the document should look something like this:

<customer>John Smith</customer>

Or something like this:

<customer>     John Smith     </customer>

Note: In the example above, the XML parser removes the tab.


String data type

Note that all of the following data types are derived from string data types (except string data types themselves)!

Name Describe
ENTITIES
ENTITY
Id Strings that commit ID properties in XML (used only with schema properties)
IDREF Strings that commit IDREF properties in XML (used only with schema properties)
IDREFS language A string that contains a legitimate language id
Name A string that contains a legitimate XML name
NCName
NMTOKEN String that commits the NMTOKEN property in XML (used with schema property only)
NMTOKENS
normalizedString Strings that do not contain line breaks, carriage returns, or tabs
Qname
string String
token Strings that do not contain line breaks, carriage returns or tabs, opening or ending spaces, or multiple consecutive spaces


Qualification of string data types (Restriction)

Qualifications that can be used with string data types:

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

That's what string data types are covered in XML Schema.