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:dWhat the engine returns
Valid asxs: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 bWhat the engine returns
Invalid asxs: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.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Schema errorsNot a valid value of the atomic typeThe message a failing name token produces during validation.
- Datatypesxs:tokenThe string type whose whitespace handling is most often confused with this one.
Related terms
- NCNameA non-colonised name: an XML name with no colon in it, which is what a namespace prefix and a local name each have to be.
- QNameA qualified name: an optional namespace prefix, a colon, and a local name — the form every element and attribute name takes in a namespaced document.
- Simple typeA schema type whose values are text with no child elements and no attributes — a string, a number, a date, or a restriction of one.
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.