XSD Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
"NCName" Datatype Values and Representations
This section describes the built-in datatype 'NCName' designed to support XML element and attribute names with no namespace prefix. 'NCName', stands for 'Non-Colonized Name', datatype is derived from 'Name' by removing ':' from the 'Name' value pattern.
If you look at string pattern used to define "Name" values, you will see colon ":" is allowed in "Name" values. This is needed to support XML element names that uses namespances like "xs:complexType".
In order to support "Name" values without ":", XSD provides another datatype called "NCName" stands for "Non-Colonized Name".
"NCName" is a datatype derived from the "Name" datatype by removing ":" from the "Name" value pattern.
Here is a sample XSD document that defines a sub element <NCName> to use "NCName" values:
<?xml version="1.1"?> <!-- NCName_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="NCName_Datatype_Test"> <xs:complexType> <xs:sequence> <xs:element name="NCName" type="xs:NCName" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Here is a sample XML document that contains <NCName> elements to test that definition:
<?xml version="1.1"?> <!-- NCName_datatype_test.xml - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <NCName_Datatype_Test> <!-- 5 valid "NCName" elements --> <NCName>name_datatype_test</NCName> <NCName>complexType</NCName> <NCName> w3.org </NCName> <NCName> head </NCName> <NCName> 头</NCName> <!-- 5 invalid "NCName" elements --> <NCName> xs:token</NCName> <NCName>complex Type</NCName> <NCName> (html)</NCName> <NCName> xs+token</NCName> <NCName> 1st_head</NCName> </NCName_Datatype_Test>
Again, the JDK tool XsdSchemaValidator.java works nicely on this test. It reports 5 groups of errors for the last 5 invalid elements. But error messages do not provide the "NCName" string pattern
Table of Contents
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
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
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