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

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.'.

Sections in This Chapter

Standard Steps to Validate XML Docuements 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

Dr. Herong Yang, updated in 2007
XSD Schema File Loading Errors