"Name" Datatype Values and Representations

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:

NameStartChar::= ([:A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF]|
                  [\u0370-\u037D\u037F-\u1FFF\u200C-\u200D]|
                  [\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF]|
                  [\uF900-\uFDCF\uFDF0-\uFFFD\u010000-\u0EFFFF]
NameChar     ::= (NameStartChar|[-.0-9\xB7\u0300-\u036F\u203F-\u2040])
Name         ::= NameStartChar(NameChar)*

"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:

Here is a sample XSD document that defines a sub element <Name> to use "Name" values:

<?xml version="1.1"?>
<!-- Name_datatype_test.xsd
 - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Name_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Name" type="xs:Name"
        maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

Here is a sample XML document that contains <Name> elements to test that definition:

<?xml version="1.1"?>
<!-- Name_datatype_test.xml
 - Copyright (c) 2002-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>   &#x5934;</Name>

<!-- 5 invalid "Name" elements -->
  <Name>complex Type</Name>
  <Name>      (html)</Name>
  <Name>    xs+token</Name>
  <Name>    1st_head</Name>
  <Name>    &#x3000;</Name>
</Name_Datatype_Test>

Run the JDK 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

herong> java 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

Table of Contents

 About This Book

 Introduction to XML Schema

 XML Editor and Schema Processor - XMLPad

 Java API for XML Processing - JAXP

 JAXP - XML Schema (XSD) Validation

 Xerces2 Java Parser - Java API of XML Parsers

 Using Xerces2 Java APIs

 XML Schema Language - Basics

 Introduction of XSD Built-in Datatypes

"string" and Its Derived Datatypes

 "string" Datatype Values and Representations

 "normalizedString" Datatype Values and Representations

 "token" Datatype Values and Representations

 "language" Datatype Values and Representations

 "language" Datatype Values - Invalid Inputs

"Name" Datatype Values and Representations

 "NMTOKEN" Datatype Values and Representations

 "NCName" Datatype Values and Representations

 "ENTITY" Datatype Values and Representations

 "ID" Datatype Values and Representations

 "IDREF" Datatype Values and Representations

 "decimal" and Its Derived Datatypes

 "dateTime" and Its Related Datatypes

 Miscellaneous Built-in Datatypes

 Facets, Constraining Facets and Restriction Datatypes

 "simpleType" - Defining Your Own Simple Datatypes

 Complex Element Declaration

 Identity-Constraints: unique, key and keyref

 Assertion as Custom Validation Rules

 XML Schema Location and Namespace in XML Documents

 Overriding Element Types in XML Documents

 Linking Multiple Schema Documents Together

 Glossary

 Archived Tutorials

 References

 Full Version in PDF/EPUB