XML Schema Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.00

Using XML Schema Built-in Datatypes Incorrectly

This section describes a tutorial example of using built-in datatypes incorrectly.

The namespace rule on built-in datatypes is very important. If you don't follow it, you will get errors we shown in the following schema examples, holiday_error.xsd:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes">

<!-- holiday_error.xsd
 - Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
-->

 <!-- Examples of incorrect built-in datatype "date" -->
 <xs:element name="holiday1" type="date"/>

 <xs:element name="holiday2" type="w3c:date"/>

 <xs:element name="holiday3" type="xsd:date"/>

</xs:schema>

Here is the output of XsdSchemaChecker.java on this schema:

>java XsdSchemaChecker holiday_error.xsd
Error:
   Line number: 10
   Column number: 43
   Message: src-resolve: Cannot resolve the name 'date' to a(n) 
   'type definition' component.

Error:
   Line number: 12
   Column number: 47
   Message: s4s-att-invalid-value: Invalid attribute value for 
   'type' in element 'element'. Recorded reason: UndeclaredPrefix:
   Cannot resolve 'w3c:date' as a QName: the prefix 'w3c' is not 
   declared.

Error:
   Line number: 14
   Column number: 47
   Message: src-resolve.4.2: Error resolving component 'xsd:date'. 
   It was detected that 'xsd:date' is in namespace 
   'http://www.w3.org/2001/XMLSchema-datatypes', but components 
   from this namespace are not referenceable from schema document 
   'file:/C:/herong/holiday_error.xsd'. If this is the incorrect 
   namespace, perhaps the prefix of 'xsd:date' needs to be changed.
   If this is the correct namespace, then an appropriate 'import' 
   tag should be added to 'file:/C:/herong/holiday_error.xsd'.

Failed with 3 errors.

The error messages are pretty clear.

Sections in This Chapter

Schema and Schema XML Representation

Checking Schema Documents - XsdSchemaChecker.java

Creating Schema Documents - "schema" Element

Declaring Root Elements - "element" Element

Specifying Element Datatype - "type" Attribute

Using XML Schema Built-in Datatypes

Using XML Schema Built-in Datatypes Incorrectly

Validating XML Documents again Schema Documents

Deriving New Simple Datatypes - "simpleType" Element

Defining Complex Datatypes - "complexType" Element

Validation Error Examples on Complex Datatypes

Dr. Herong Yang, updated in 2007
Using XML Schema Built-in Datatypes Incorrectly