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

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.

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 2009
Validation Error Examples on Complex Datatypes