This section describes the built-in datatype 'NMTOKEN' designed to support XML 'NMTOKEN' attribute values. 'NMTOKEN' datatype is derived from 'token' by restricting the value set according the XML 'NMTOKEN' specification.
The third datatype derived from "token" is "NMTOKEN", which is designed
to support "NMTOKEN" attribute values defined in the XML 1.1 specification.
"NMTOKEN" (stands for Name Token) is a datatype derived from "token" datatype
by limiting values to those satisfy the following pattern defined in XML 1.1:
If you comparing this pattern with the "Name" datatype pattern,
you will see that "NMTOKEN" value set is slightly bigger than "Name" value set.
"NMTOKEN" values accept [-.0-9\xB7\u0300-\u036F\u203F-\u2040] as the
first non white-space character.
Here is a sample XSD document that defines a sub element <NMTOKEN> to use "NMTOKEN" values:
Here is a sample XML document that contains <NMTOKEN> elements to test that definition:
<?xml version="1.1"?>
<!-- NMTOKEN_datatype_test.xml
- Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<NMTOKEN_Datatype_Test>
<!-- 6 valid "NMTOKEN" elements -->
<NMTOKEN>NMTOKEN_datatype_test</NMTOKEN>
<NMTOKEN> html </NMTOKEN>
<NMTOKEN> xs:token</NMTOKEN>
<NMTOKEN> .htaccess </NMTOKEN>
<NMTOKEN> 头</NMTOKEN>
<NMTOKEN> 2nd_place</NMTOKEN>
<!-- 4 invalid "NMTOKEN" elements -->
<NMTOKEN>complex Type</NMTOKEN>
<NMTOKEN> (html)</NMTOKEN>
<NMTOKEN> xs+token</NMTOKEN>
<NMTOKEN>  </NMTOKEN>
</NMTOKEN_Datatype_Test>
Run the JDK 1.7 tool XsdSchemaValidator.java again,
you will see 4 groups of errors for the last 4 invalid elements.
But error messages do not provide the "NMTOKEN" string pattern
c:\Progra~1\Java\jdk1.7.0_07\bin\java.exe XsdSchemaValidator
NMTOKEN_datatype_test.xsd NMTOKEN_datatype_test.xml
...
Error:
Line number: 17
Column number: 34
Message: cvc-datatype-valid.1.2.1: 'xs+token' is not a valid value
for 'NMTOKEN'.
Error:
Line number: 17
Column number: 34
Message: cvc-type.3.1.3: The value 'xs+token' of element 'NMTOKEN'
is not valid.
Error:
Line number: 18
Column number: 34
Message: cvc-datatype-valid.1.2.1: '?' is not a valid value for
'NMTOKEN'.
Error:
Line number: 18
Column number: 34
Message: cvc-type.3.1.3: The value '?' of element 'NMTOKEN' is not
valid.