This section describes the built-in datatype 'Name' designed to support XML element and attribute names. 'Name' datatype is derived from 'token' by restricting the value set according the XML 'Name' specification.
The second datatype derived from "token" is "Name", which is designed
to support "Name" strings define in the XML 1.1 specification.
"Name" is a datatype derived from "token" datatype
by limiting values to those satisfy the following pattern defined in XML 1.1:
"Name" strings are defined to be used as element names and attribute names in XML documents.
According the above definition, we can use non-English characters in "Name" strings.
In other words, we can use Chinese characters as XML element or attribute names.
Similar to "language" datatype, input lexical representations of "Name" datatype will be
validated and evaluated in 2 steps:
First, covert the input lexical representation into an intermediate "token" value.
Then, apply the "Name" pattern on the "token" value.
If a match found, the input lexical representation is a valid "Name" lexical representation and the "Token" value is the "Name" value.
If no match found, the input lexical representation is not a valid "Name" lexical representation.
Here is a sample XSD document that defines a sub element <Name> to use "Name" values:
Here is a sample XML document that contains <Name> elements to test that definition:
<?xml version="1.1"?>
<!-- Name_datatype_test.xml
- Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<Name_Datatype_Test>
<!-- 6 valid "Name" elements -->
<Name>name_datatype_test</Name>
<Name>complexType</Name>
<Name> html </Name>
<Name> xs:token</Name>
<Name> head </Name>
<Name> 头</Name>
<!-- 5 invalid "Name" elements -->
<Name>complex Type</Name>
<Name> (html)</Name>
<Name> xs+token</Name>
<Name> 1st_head</Name>
<Name>  </Name>
</Name_Datatype_Test>
Run the JDK 1.7 tool XsdSchemaValidator.java again,
you will see 5 groups of errors for the last 5 invalid elements.
But error messages do not provide the "Name" string pattern
c:\Progra~1\Java\jdk1.7.0_07\bin\java.exe XsdSchemaValidator
Name_datatype_test.xsd Name_datatype_test.xml
...
Error:
Line number: 19
Column number: 28
Message: cvc-datatype-valid.1.2.1: '1st_head' is not a valid value
for 'Name'.
Error:
Line number: 19
Column number: 28
Message: cvc-type.3.1.3: The value '1st_head' of element 'Name' is
not valid.
Error:
Line number: 20
Column number: 28
Message: cvc-datatype-valid.1.2.1: '?' is not a valid value for
'Name'.
Error:
Line number: 20
Column number: 28
Message: cvc-type.3.1.3: The value '?' of element 'Name' is not
valid.
Failed with errors: 10