JDK Tutorials - Herong's Tutorial Examples - Version 5.11, by Dr. Herong Yang

XML XSD Schema Validation Test Result

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>

Here is the linked XSD file, dictionary.xsd:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:element name="dictionary" type="dictionaryType"/>
 <xsd:complexType name="dictionaryType">
  <xsd:sequence>
   <xsd:element name="word" type="wordType" maxOccurs="unbounded"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="wordType">
  <xsd:sequence>
   <xsd:element name="name" type="xsd:string"/>
   <xsd:element name="definition" type="definitionType" 
    maxOccurs="unbounded"/>
   <xsd:element name="update" type="updateType" minOccurs="0"/>
  </xsd:sequence>
  <xsd:attribute name="acronym" type="xsd:boolean" use="optional"/>
  <xsd:attribute name="symbol" type="xsd:boolean" use="optional"/>
 </xsd:complexType>
 <xsd:complexType name="definitionType" mixed="true">
  <xsd:attribute name="reference" type="xsd:string"/>
 </xsd:complexType>
 <xsd:complexType name="updateType">
  <xsd:attribute name="date">
   <xsd:simpleType>
    <xsd:restriction base="xsd:string">
     <xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}"/>
    </xsd:restriction>
   </xsd:simpleType>
  </xsd:attribute>
 </xsd:complexType>
</xsd:schema>

Now run the XMLReaderValidator program:

java -cp .;\local\xerces-2_3_0\xercesImpl.jar XMLReaderValidator
   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 provides a list of errors with exact error locations and full error descriptions.

Last update: 2006.

Table of Contents

 About This JDK Tutorial Book

 Downloading and Installing JDK 1.7.0 on Windows

 Downloading and Installing JDK 1.6.2 on Windows

 Downloading and Installing JDK 1.5.0 on Windows

 Downloading and Installing JDK 1.4.1 on Windows

 Downloading and Installing JDK 1.3.1 on Windows

 Date, Time and Calendar Classes

 Date and Time Object and String Conversion

 Number Object and Numeric String Conversion

 Locales, Localization Methods and Resource Bundles

 Calling and Importing Classes Defined in Unnamed Packages

 HashSet, Vector, HashMap and Collection Classes

 Character Set Encoding Classes and Methods

 Character Set Encoding Maps

 Encoding Conversion Programs for Encoded Text Files

 Socket Network Communication

 Datagram Network Communication

 DOM (Document Object Model) - API for XML Files

 SAX (Simple API for XML)

 DTD (Document Type Definition) - XML Validation

XSD (XML Schema Definition) - XML Validation

 XML XSD Schema Validation with Xerces

XML XSD Schema Validation Test Result

 Loading External XML Parsers with SAXParserFactory

 XSL (Extensible Stylesheet Language)

 Message Digest Algorithm Implementations in JDK

 Private key and Public Key Pair Generation

 PKCS#8/X.509 Private/Public Encoding Standards

 Digital Signature Algorithm and Sample Program

 "keytool" Commands and "keystore" Files

 KeyStore and Certificate Classes

 Secret Key Generation and Management

 Cipher - Secret Key Encryption and Decryption

 The SSL (Secure Socket Layer) Protocol

 SSL Socket Communication Testing Programs

 SSL Client Authentication

 HTTPS (Hypertext Transfer Protocol Secure)

 References

 PDF Printing Version

XML XSD Schema Validation Test Result - Updated in 2014, by Dr. Herong Yang