-
The value of
NMTOKENfollows the same rules as XML name, except withNMTOKENany of the allowed characters can be the first character. Unlike XMLstringtype,NMTOKENvalues can’t contain any whitespace. Still I fail to see its usefulness.So when and why would we use
NMTOKENtype instead of astringtype? -
NMTOKENSenables us to specify severalNMTOKENvalues (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 bothNMTOKENStype andstringtype can hold exactly the same values.So when is this type useful?
The value of NMTOKEN follows the same rules as XML name, except with NMTOKEN
Share
NMTOKENandNMTOKENSexist 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
NMTOKENandNMTOKENSwhen 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:stringorxs:tokenand constrain as needed with apatternfacet. Or, more commonly in my experience, usexs:stringorxs:tokenas-is and call it close enough.