Java validating xml against schema
Sample Invalid Servlet 2.5 (web-invalid.xml) As the last output shows, things are more interesting in terms of output when the provided XML is not XSD valid.
There is one important caveat I wish to emphasize here.
In most cases, I have tried to comment the code that requires JDK 7 or JDK 8 to identify these dependencies and provide alternative approaches in earlier versions of Java.
I have done this so that the tool can be adapted to work even in environments with older versions of Java.
This is the reason why (most of the) XML parser implementations do not support XML Namespaces by default, to handle the validation of XML documents with namespaces correctly it is therefore necessary to configure the underlying parsers to provide support for XML Namespaces.
* * This method can be commented out if using a version of * Java prior to JDK 8.
The input document contains an extra attribute which has not been defined in the XML Schema, this shows that the XML Schema has been used for the validation.