XSD Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
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:
herong> javaXsdSchemaLoader 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:/herong/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:
(JDK 13) herong> javaXsdSchemaLoader XsdSchemaLoader.java org.xml.sax.SAXParseException: Content is not allowed in prolog. org.xml.sax.SAXParseException; systemId: file:/herong/xsd/XsdSchemaLoader.java; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. (JDK 1.6) herong> javaXsdSchemaLoader 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:
(JDK 13) herong> java XsdSchemaLoader first_html.xml org.xml.sax.SAXParseException; systemId: file:/herong/xsd/first_html.xml; lineNumber: 3; columnNumber: 46; 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.'. (JDK 1.6) herong> 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.'.
As you can see, the error messages have been improved since JDK 1.6.
Table of Contents
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
XSD 1.1 Not Supported in JDK 13
Xerces2 Java Parser - Java API of XML Parsers
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
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