XSD Tutorials - Herong's Tutorial Examples - v5.21, by Dr. Herong Yang
Outdated: Running XMLReaderValidator with Xerces2 2.11.0 Beta
This section describes a tutorial example on how to the Xerces2 XMLReader class to validate an XML document assigned with an XSD file with 'Xerces2 2.11.0 (XML Schema 1.1) (Beta)' version.
Now I am ready to test the "Xerces2 2.11.0 (XML Schema 1.1) (Beta)" version, with the same program, XMLReaderValidator:
herong> java ^^^ -cp ".;c:\local\xerces-2_11_0-xml-schema-1.1-beta\xercesImpl.jar" ^^^ XMLReaderValidator dictionary_invalid_xsd.xml Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/wst/xml/xpath2/processor/XPathParserException at org.apache.xerces.impl.xs.traversers.XSDHandler.createTravers... at org.apache.xerces.impl.xs.traversers.XSDHandler.prepareForTra... at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(U... at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown ... at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGramma... at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartEleme... at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unk... at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElem... at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDisp... at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$Fragmen... at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDoc... at org.apache.xerces.parsers.XML11Configuration.parse(Unknown So... at org.apache.xerces.parsers.XML11Configuration.parse(Unknown So... at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Sou... at XMLReaderValidator.main(XMLReaderValidator.java:24) Caused by: java.lang.ClassNotFoundException: org.eclipse.wst.xml.xpath2.processor.XPathParserException at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 16 more
I am surprised to see this ClassNotFoundException error. But it is not hard to fix it. The missing class is actually provided in org.eclipse.wst.xml.xpath2.processor_1.1.0.jar in the "Xerces2 2.11.0 (XML Schema 1.1) (Beta)" package. You can all all JAR files from the Xerces2 package to the classpath to avoid any ClassNotFoundException errors.
Rerunning XMLReaderValidator with org.eclipse.wst.xml.xpath2.processor_1.1.0.jar included in the classpath, I get the correct validation result:
herong> java ^^^ -cp ".;c:\local\xerces-2_11_0-xml-schema-1.1-beta\xercesImpl.jar; ^^^c:\local\xerces-2_11_0-xml-schema-1.1-beta\org.eclipse.wst.xml.xpath2.processor_1.1.0.jar" ^^^ XMLReaderValidator dictionary_invalid_xsd.xml Error: Public ID: null System ID: file:///C:/herong/dictionary_invalid_xsd.xml Line number: 7 Column number: 22 Message: cvc-datatype-valid.1.2.1: 'yes' is not a valid value for 'boolean'. ...
Table of Contents
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
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
Linking Multiple Schema Documents Together
Outdated: Xerces2 Java 2.11.0 XML Schema 1.1 Beta
►Outdated: Running XMLReaderValidator with Xerces2 2.11.0 Beta