Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the usefulness of NMTOKEN and NMTOKENS types?

Tags:

  1. The value of NMTOKEN follows the same rules as XML name, except with NMTOKEN any of the allowed characters can be the first character. Unlike XML string type, NMTOKEN values can’t contain any whitespace. Still I fail to see its usefulness.

    So when and why would we use NMTOKEN type instead of a string type?

  2. NMTOKENS enables us to specify several NMTOKEN values (separated by whitespace) in a single string. This type makes even less sense, since it also allows a value to contain whitespace characters, which essentially means that both NMTOKENS type and string type can hold exactly the same values.

    So when is this type useful?

like image 613
flockofcode Avatar asked Apr 27 '11 18:04

flockofcode


People also ask

What is NMTOKENS?

Description. The lexical and value spaces of xs:NMTOKEN are the set of XML 1.0 “name tokens,” i.e., tokens composed of characters, digits, “.”, “:”, “-”, and the characters defined by Unicode, such as “combining” or “extender”.

What is the Nmtoken attribute type?

An NMTOKEN (name token) is any mixture of Name characters. It cannot contain whitespace (although leading or trailing whitespace will be trimmed/ignored).


1 Answers

NMTOKEN and NMTOKENS exist in XML Schema only for compatibility with DTDs, the predecessor of XML Schema, which had those as attributes types. DTD has few other types so those don't stand out as redundant there.

So use NMTOKEN and NMTOKENS when you're converting a DTD to an XML Schema.

Addendum: Those and other all caps types fall into the same category. They are marked in the XML Schema Rec with the text, "For compatibility NMTOKEN should be used only on attributes."

If they exactly fit your needs, it might be easiest to use just them, but the XML Schema way is to derive from xs:string or xs:token and constrain as needed with a pattern facet. Or, more commonly in my experience, use xs:string or xs:token as-is and call it close enough.

like image 99
xan Avatar answered Sep 18 '22 12:09

xan