This section provides a tutorial example on validating XML documents with XSD 1.1 schema using 'Xerces2 2.11.0 (XML Schema 1.1) (Beta)' version.
First, let's see if my Xsd11SchemaValidator.java program will work with the Xerces2 version integrated in JDK 1.7:
c:\Progra~1\Java\jdk1.7.0_07\bin\javac Xsd11SchemaValidator.java
c:\Progra~1\Java\jdk1.7.0_07\bin\java Xsd11SchemaValidator
xsd11_datatype_test.xsd xsd11_datatype_test.xml
java.lang.IllegalArgumentException: No SchemaFactory that implements
the schema language specified by:
http://www.w3.org/XML/XMLSchema/v1.1 could be loaded
java.lang.NullPointerException
I am surprised on this error. I knew that the Xerces2 version integrated in JDK 1.7 does not support XSD 1.1.
So now run it again with the "Xerces2 2.11.0 (XML Schema 1.1) (Beta)" version:
c:\Progra~1\Java\jdk1.7.0_07\bin\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"
Xsd11SchemaValidator
xsd11_datatype_test.xsd xsd11_datatype_test.xml
Error:
Line number: 17
Column number: 67
Message: cvc-type.3.1.2: Element 'AnyAtomicType' is a simple type,
so it must have no element information item [children].
Error:
Line number: 23
Column number: 51
Message: cvc-datatype-valid.1.2.1: '?' is not a valid value for
'dateTimeStamp'.
Error:
Line number: 23
Column number: 51
Message: cvc-type.3.1.3: The value ' ? ' of element
'DateTimeStamp' is not valid.
Error:
Line number: 29
Column number: 65
Message: cvc-datatype-valid.1.2.1: 'P1Y2M3DT5H20M30.123S' is not a
valid value for 'dayTimeDuration'.
Error:
Line number: 29
Column number: 65
Message: cvc-type.3.1.3: The value ' P1Y2M3DT5H20M30.123S '
of element 'DayTimeDuration' is not valid.
Error:
Line number: 35
Column number: 69
Message: cvc-datatype-valid.1.2.1: 'P1Y2M3DT5H20M30.123S' is not a
valid value for 'yearMonthDuration'.
Error:
Line number: 35
Column number: 69
Message: cvc-type.3.1.3: The value ' P1Y2M3DT5H20M30.123S
' of element 'YearMonthDuration' is not valid.
Failed with errors: 7
Congratulations, we have successfully validated an XML document with a XSD 1.1 document!