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.

Names and namespaces

NMTOKEN

A name token: any string of XML name characters, with no restriction on what it starts with.

An NMTOKEN is the loosest of the name types. It uses the same character repertoire as a name, but drops the rule about the first character — so "2026", "-draft" and "a:b" are all legal NMTOKENs while none of them is a legal element name.

It exists for attribute values that need to look like identifiers without being them: version numbers, enumerated codes, class-like tokens. The one thing it still forbids is whitespace, which is what separates NMTOKEN from NMTOKENS.

Defined in
XML 1.0 §2.3
Category
Names and namespaces
Also written
name token

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.

  • An NMTOKEN may start with a digit and may contain a colon.

    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:NMTOKEN"/>
    </xs:schema>
    value
    a-b.c:d

    What the engine returns

    Valid as xs:NMTOKEN.
  • But it may not contain a space — that would be two tokens.

    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:NMTOKEN"/>
    </xs:schema>
    value
    a b

    What the engine returns

    Invalid as xs:NMTOKEN.

What catches people out

  • NMTOKEN and NCName are not ordered by strictness in the obvious way: NMTOKEN allows a leading digit but NCName forbids a colon, so neither accepts everything the other does.
  • Whitespace makes it NMTOKENS, a list type. A single-valued attribute typed NMTOKEN will reject the space rather than trimming it.
  • Validators report this as an atomic type failure, which names the type but not the character that broke it.

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.