sax.Writer Reporting Errors Embedded in XML Structure

This section provides a tutorial example showing sax.Writer reporting XSD validation errors embedded inside XML structure.

Now let's rerun sax.Writer on dictionary_invalid_xsd.xml and see how it reports those errors:

herong> java_xerces sax.Writer -v -s dictionary_invalid_xsd.xml

<?xml version="1.0" encoding="UTF-8"?>
<dictionary xsi:noNamespaceSchemaLocation="dictionary.xsd">

 [Error] dictionary_invalid_xsd.xml:7:22: cvc-datatype-valid.1.2.1:
^^^ 'yes' is not a valid value for 'boolean'.
[Error] dictionary_invalid_xsd.xml:7:22: cvc-attribute.3: The value
^^^ 'yes' of attribute 'acronym' on element 'word' is not valid with
^^^ respect to its type, 'boolean'.
<word acronym="yes">

  [Error] dictionary_invalid_xsd.xml:8:10: cvc-complex-type.2.4.a:
^^^ Invalid content was found starting with element 'names'. One of
^^^ '{name}' is expected.
<names>XML</names>
  <definition reference="Herong's Notes">eXtensible Markup
Language.</definition>

  [Error] dictionary_invalid_xsd.xml:11:31: cvc-pattern-valid: Value
^^^ '23-Dec-2003' is not facet-valid with respect to pattern
^^^ '\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}' for type
^^^ '#AnonType_dateupdateType'.

[Error] dictionary_invalid_xsd.xml:11:31: cvc-attribute.3: The value
^^^ '23-Dec-2003' of attribute 'date' on element 'update' is not valid
^^^ with respect to its type, '#AnonType_dateupdateType'.
<update date="23-Dec-2003"></update>
 </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>

  [Error] dictionary_invalid_xsd.xml:20:33: cvc-complex-type.3.2.2:
^^^ Attribute 'editor' is not allowed to appear in element 'update'.
<update editor="Herong Yang"></update>
 </word>

 [Error] dictionary_invalid_xsd.xml:22:36: cvc-datatype-valid.1.2.1:
^^^ 'no' is not a valid value for 'boolean'.

[Error] dictionary_invalid_xsd.xml:22:36: cvc-attribute.3: The value
^^^ 'no' of attribute 'symbol' on element 'word' is not valid with
^^^ respect to its type, 'boolean'.
<word acronym="false" symbol="no">
  <name>extensible</name>
  <definition>Capable of being extended.</definition>
 </word>
</dictionary>

Really nice! All errors are reported where they occurred.

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

 Installing Xerces2 Java Parser for XSD 1.1

 Verify Installation of Xerces2

 Xerces2 Sample Program List

 Xerces2 Sample Program dom.Counter

 dom.Counter Validating XML with Associated XSD

 dom.GetElementsByTagName and dom.Writer

 sax.DocumentTracer and sax.Writer

 Examples of XSD and XML Files with Errors

sax.Writer Reporting Errors Embedded in XML Structure

 XSD 1.1 not Supported by sax.Writer

 XSD 1.1 Supported by jaxp.SourceValidator

 Examples of XSD 1.1 and XML Files with Errors

 jaxp.TypeInfoWriter as an XSD 1.1 Validation Tool

 Using Xerces2 Java APIs

 XML Schema Language - Basics

 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

 Archived Tutorials

 References

 Full Version in PDF/EPUB