Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

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
      padded  

    What the engine returns

    Valid as xs: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 out 

    What the engine returns

    Invalid as xs: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.

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.