This section provides a tutorial example on how to run the XML schema validation program, XMLReaderValidator.java. The result provides errors with detailed locations and descriptions.
In order to test my XML schema validator, XMLReaderValidator.java,
I prepared the following 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) 2002 by Dr. Herong Yang
-->
<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>
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 provides a list of errors with exact error locations and full error descriptions.