XSD Tutorials - Herong's Tutorial Examples - Version 5.10, by Dr. Herong Yang

Validation Error Examples on Complex Datatypes

This section describes a tutorial example on XML document validation errors related to a complex datatype defined a schema.

To see some examples of the validation errors on elements using complex datatypes, I wrote the following XML document, term_error.xml:

<?xml version="1.0"?>
<term update="Yesterday" note="To be updated.">
 <source>Internet</source>
 <name>Extensible</name>
 <definition>Capable of being extended.</definition>
</term>

Of course, this XML document does not conform to term.xsd. Here are the errors generated from XsdSchemaValidator.java:

>java XsdSchemaValidator term.xsd term_error.xml

Error:
   Line number: 2
   Column number: 48
   Message: cvc-datatype-valid.1.2.1: 'Yesterday' is not a valid 
   value for 'date'.

Error:
   Line number: 2
   Column number: 48
   Message: cvc-attribute.3: The value 'Yesterday' of attribute 
   'update' on element 'term' is not valid with respect to its 
   type, 'date'.

Error:
   Line number: 2
   Column number: 48
   Message: cvc-complex-type.3.2.2: Attribute 'note' is not allowed
   to appear in element 'term'.

Error:
   Line number: 3
   Column number: 10
   Message: cvc-complex-type.2.4.a: Invalid content was found 
   starting with element 'source'. One of '{name}' is expected.

Failed with errors: 4

For more tutorials on complex datatypes, read other chapters of this book.

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

 Glossary

 References

 PDF Printing Version

Validation Error Examples on Complex Datatypes - Updated in 2014, by Dr. Herong Yang