Latest web development tutorials

XML Schema string data type

String data type is used to contain the value of the string.


String data type (String Data Type)

String data type can contain characters, line feeds, carriage returns, and tabs.

Here is an example of a scheme string declaration:

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

Elements in the document should look like this:

<customer>John Smith</customer>

Or like this:

<customer> John Smith </customer>

Note: If you use the string data types, XML processor will not change one value.


Normalized string data type (NormalizedString Data Type)

Normalized string data types derived from string data type.

Normalized string data type can contain the same characters, but the XML processor will remove line break, carriage returns, and tabs.

Here is an example of a normalized string data type in the schema:

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

Elements in the document should look like this:

<customer>John Smith</customer>

Or like this:

<customer> John Smith </customer>

Note: In the above example, XML processor will be used to replace all tabs with spaces.


Token data type (Token Data Type)

Token data derived from the same type of string data type.

Token same data type can contain characters, but the XML processor will remove line feeds, carriage returns, tabs, leading and trailing spaces, and (continuous) space.

Here is an example of a schema in the relevant token declaration:

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

Elements in the document should look like this:

<customer>John Smith</customer>

Or like this:

<customer> John Smith </customer>

Note:> In the above example, XML parser will remove the tabs.


String data type

Please note that all of the following data types are derived from the String data type (except for string data type itself)!

name description
ENTITIES
ENTITY
ID Submitted string ID attribute in XML (only used in conjunction with schema attributes)
IDREF Submitted string IDREF attribute in XML (only used in conjunction with schema attributes)
IDREFS language String contains a valid language id of
Name String contains a valid XML name
NCName
NMTOKEN Submitted string NMTOKEN attribute in XML (only used in conjunction with schema attributes)
NMTOKENS
normalizedString String does not contain line feeds, carriage returns, or tabs
QName
string String
token String does not contain line feeds, carriage returns, or tabs, leading or trailing spaces or more consecutive spaces


String data type defined (Restriction)

It can be used in conjunction with a defined string data types:

  • enumeration
  • length
  • maxLength
  • minLength
  • pattern (NMTOKENS, IDREFS, and ENTITIES can not use this constraint)
  • whiteSpace