XSD Schema File Loading Errors

This section describes tutorial examples of different error cases when loading an XSD schema file with JAXP Schema and SchemaFactory classes.

If you try to use XsdSchemaLoader.java to load an XSD file that does no exist, you will some interesting error messages:

>java XsdSchemaLoader wrong.xsd

Schema Language: http://www.w3.org/2001/XMLSchema
Factory Class: com.sun.org.apache.xerces.internal.jaxp
   .validation.XMLSchemaFactory

org.xml.sax.SAXParseException: schema_reference.4: 
Failed to read schema document 'file:/C:/xsd/wrong.xsd', because 
1) could not find the document; 
2) the document could not be read; 
3) the root element of the document is not <xsd:schema>.

If you try to use XsdSchemaLoader.java to load a non-XML file as the XSD file, you will get an XML parsing error:

>java XsdSchemaLoader XsdSchemaLoader.java

org.xml.sax.SAXParseException: Content is not allowed in prolog.

If you try to use XsdSchemaLoader.java to load a regular XML file as the XSD file, you will get an XML Schema syntax error:

>type first_html.xml
<?xml version = "1.0" encoding = "utf-8"?>
<html>
<body>My first HTML document in XML format.</body>
</html>

>java XsdSchemaLoader first_html.xml

org.xml.sax.SAXParseException: s4s-elt-character: 
Non-whitespace characters are not allowed in schema elements other 
than 'xs:appinfo' and 'xs:documentation'. 
Saw 'My first HTML document in XML format.'.

Last update: 2013.

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

 Standard Steps to Validate XML Documents Against a Schema

 XSD Schema File Loader - XsdSchemaLoader.java

XSD Schema File Loading Errors

 XSD Schema XML DOM Validator - XsdSchemaDomValidator.java

 XSD Schema XML DOM Validation Errors

 XSD Schema XML DOM Validator with Error Handler

 XSD Schema XML SAX Validator - XsdSchemaSaxValidator.java

 XSD Schema XML SAX Validation Errors

 XSD Schema XML SAX Validator with Error Handler

 XSD Schema XML Validator - Final Version

 Xerces2 Java Parser - Java API of XML Parsers

 Using Xerces2 Java API

 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

 References

 PDF Printing Version