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

XMLReaderValidator.java - Validation Error Messages

This section provides a tutorial example on how to review validation error message generated by the sample program, XMLReaderValidator.java, on an XML file that does not meet rules specified in its linked XSD schema file.

Here is an XML file, dictionary_invalid_xsd.xml:

<?xml version="1.0"?>
<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:noNamespaceSchemaLocation="dictionary.xsd">
<!-- dictionary_invalid_xsd.xml
   Copyright (c) 2012, HerongYang.com, All Rights Reserved.
-->
 <word acronym="yes">
  <name>XML</name>
  <definition reference="Herong's Notes">eXtensible Markup 
Language.</definition>
  <update date="23-Dec-2003"/>
 </word>
 <word symbol="true">
  <name><</name>
  <definition>Mathematical symbol representing the "less than" logical 
operation, like: 1<2.</definition>
  <definition>Reserved symbol in XML representing the beginning of 
tags, like: <![CDATA[<p>Hello world!</p>]]>
  </definition>
  <update editor="Herong Yang"/>
 </word>
 <word symbol="no" acronym="false">
  <name>extensible</name>
  <definition>Capable of being extended.</definition>
 </word>
</dictionary>

Now run the XMLReaderValidator program:

java -cp .;\local\xerces-2_3_0\xercesImpl.jar dictrionary_invalid_xsd.xml

you will get:

Error:
   Public ID: null
   System ID: file:///D:/herong/dictionary_invalid_xsd.xml
   Line number: 7
   Column number: 22
   Message: cvc-datatype-valid.1.2.1: 'yes' is not a valid 'boolean' 
value.
Error:
   Public ID: null
   System ID: file:///D:/herong/dictionary_invalid_xsd.xml
   Line number: 7
   Column number: 22
   Message: cvc-attribute.3: The value 'yes' of attribute 'acronym' on 
element 'word' is not valid with respect to its type.
Error:
   Public ID: null
   System ID: file:///D:/herong/src/dictionary_invalid_xsd.xml
   Line number: 11
   Column number: 31
   Message: cvc-pattern-valid: Value '23-Dec-2003' is not facet-valid 
with respect to pattern '\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}'.
Error:
   Public ID: null
   System ID: file:///D:/herong/dictionary_invalid_xsd.xml
   Line number: 11
   Column number: 31
   Message: cvc-attribute.3: The value '23-Dec-2003' of attribute 'date'
on element 'update' is not valid with respect to its type.
Error:
   Public ID: null
   System ID: file:///D:/herong/dictionary_invalid_xsd.xml
   Line number: 20
   Column number: 33
   Message: cvc-complex-type.3.2.2: Attribute 'editor' is not allowed to
appear in element 'update'.
Error:
   Public ID: null
   System ID: file:///D:/herong/dictionary_invalid_xsd.xml
   Line number: 22
   Column number: 36
   Message: cvc-datatype-valid.1.2.1: 'no' is not a valid 'boolean' 
value.
Error:
   Public ID: null
   System ID: file:///D:/herong/dictionary_invalid_xsd.xml
   Line number: 22
   Column number: 36
   Message: cvc-attribute.3: The value 'no' of attribute 'symbol' on 
element 'word' is not valid with respect to its type.

This is perfect. It tells you where the error is, and why it's an error.

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 DOM (Document Object Model) Programming Interface

 SAX (Simple API for XML) Programming Interface

 DTD (Document Type Definition) Introduction

 Syntaxes of DTD Statements

 Validating an XML Document against the Specified DTD Document Type

 XSD (XML Schema Definition) Introduction

 Syntaxes of XSD Statements

Validating an XML Document against the Specified XML Schema

 XMLReaderValidator.java - Validating XML with XSD using Xerces-J

XMLReaderValidator.java - Validation Error Messages

 Using SAXParserFactory to Load XML Parsers

 XSL (Extensible Stylesheet Language) Introduction

 XSLT (XSL Transformations) Introduction

 Java Implementation of XSLT

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 References

 Printable Copy - PDF Version

Dr. Herong Yang, updated in 2013
XMLReaderValidator.java - Validation Error Messages