XSD datatype
xs:string
Any sequence of legal XML characters, with whitespace preserved exactly. The only string type that does not touch your value.
xs:string is the primitive every other string type derives from. Its whiteSpace facet is fixed at 'preserve', which means leading, trailing and internal whitespace all survive validation untouched.
That is usually what you want for human text and almost never what you want for identifiers. A value that arrives as ' A-1001 ' is a different string from 'A-1001', and comparisons downstream will treat it that way.
- Lexical space
- Any string of characters legal in XML 1.0.
- Derives from
- Primitive type
- Category
- String types
- Facets
- length, minLength, maxLength, pattern, enumeration, whiteSpace
What validates
Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.
Ada Lovelacepadded(the empty string)line breakemoji 😀
What does not
Nothing — this type accepts any legal XML character content. That is worth knowing: it constrains nothing on its own, so any real restriction has to come from a facet.
What catches people out
- Whitespace is preserved, including a value that is entirely whitespace. Use xs:token when you want it collapsed.
- The empty string is a valid xs:string. If an element must have content, constrain it with minLength rather than assuming.
- Characters illegal in XML 1.0 cannot appear at all — that is a parse error before validation is reached.
The schema used
This is the exact schema the literals above are validated against. Paste it into the validator with one of them to see the result yourself.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="v" type="xs:string"/>
</xs:schema>Related
- xs:tokenA string trimmed of leading and trailing whitespace, with internal runs collapsed to one space. The right type for most identifiers.
- xs:normalizedStringA string with tabs, newlines and carriage returns replaced by spaces — but not trimmed and not collapsed.
- minLength, maxLength and lengthBounds on size — measured in characters for strings, list items for lists, and bytes for binary.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.