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

<!-- holiday_error.xsd
 - Copyright (c) 2013,, 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"/>


Here is the output of on this schema:

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

   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 

   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 
   '', 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.

Last update: 2013.

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 API

XML Schema Language - Basics

 Schema and Schema XML Representation

 Checking Schema Documents -

 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 against Schema Documents

 Deriving New Simple Datatypes - "simpleType" Element

 Defining Complex Datatypes - "complexType" Element

 Validation Error Examples on Complex Datatypes

 Introduction of XSD Built-in Datatypes

 "string" and Its Derived Datatypes

 "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



 PDF Printing Version