Schemas and validity
Simple type
A schema type whose values are text with no child elements and no attributes — a string, a number, a date, or a restriction of one.
Simple types are where XSD's datatype library lives. You either use a built-in one directly or derive a new type from it by restriction — adding facets that narrow what counts as a legal value — by list, or by union.
An element declared with a simple type can have neither children nor attributes. Wanting an attribute on an element whose content is a plain value is what forces the step up to a complex type with simple content, which is the most-searched corner of the schema language.
- Defined in
- XSD 1.0 §3.14
- Category
- Schemas and validity
- Also written
- xs:simpleType
Shown, not asserted
All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.
Whitespace is collapsed before the value is judged, so the padding here simply disappears.
schema.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="v" type="xs:token"/> </xs:schema>value paddedWhat the engine returns
Valid asxs:token.Collapsing cannot rescue an interior space, though: NCName still rejects this.
schema.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="v" type="xs:NCName"/> </xs:schema>value spaced outWhat the engine returns
Invalid asxs:NCName.
What catches people out
- An element with a simple type cannot carry attributes. You need complexType with simpleContent for that.
- Whitespace processing happens before facets are checked, so a length facet counts the processed value.
- Restriction narrows a type and can never widen it: you cannot add values back that the base type excluded.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Datatypesxs:tokenThe type used above, and the whitespace handling that surprises people.
- Datatypesxs:stringThe primitive every string type derives from.
- Schema errorsNot a valid value of the atomic typeThe message a bad value against a simple type produces.
Related terms
- Complex typeA schema type for elements that have children, attributes, or both — everything a simple type cannot describe.
- FacetA constraint that narrows a simple type: a length, a range, a regular expression, a list of permitted values.
- XML Schema (XSD)The W3C schema language: a grammar written in XML itself, with datatypes, namespaces and a type system.
- NMTOKENA name token: any string of XML name characters, with no restriction on what it starts with.
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.