An implementation of the Java XML validation API SchemaFactory
to validate XML documents against their own declared grammars.
This Maven artifact can be added as a dependency for any JAXP-compliant(2) validator, such as the XML Maven Plugin.
You can find a example here : https://github.com/labo-jim/intrinsic-validator-test-project
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
final String schemaLanguage = "http://componentcorp.com/xml/ns/xml-model/1.0";
SchemaFactory intrinsicSchemaFactory = SchemaFactory.newInstance(schemaLanguage);
Schema schema = intrinsicSchemaFactory.newSchema();
Validator validator = schema.newValidator();
Source yourXML = Your XML...
validator.validate(yourXML);
The instanciation of a SAX ValidatorHandler
is not supported for several reasons(1) (cf. below).
- The Intrinsic JAXP Validator will launch a SAX parsing of the document being
validating to fetch :
- The
xml-model
processing instrunction - (In a further release), the
xsi:@*
XML Schema Instance Attributes
- The
- After that, it will instanciate a
Validator
for each declared grammar found, and validate the document against it.
The Intrinsic JAXP Validator is designed under the KISS principle.
It is simple and stupid.
The Intrinsic JAXP Validator does not handle himself any validation process.
It will simply instanciate a SchemaFactory
for the declared schemma language.
This meens that you, of course, need to have a matching JAXP-compliant(2) implementation of each schema type you use in your classpath.(3)
- Why not supporting the SAX validation (i.e. with a
ValidatorHandler
)- Because the goal of this helper is to validate XML documents against various Schema type, including the unusual suspects, i.e. Schematron and NVDL, for witch no SAX implementation is available.
- Since who can do more can do less, validators that implements the
ValidatorHandler
also implements theValidator
- JAXP stands for JAva XML Processing API.
cf. <https://docs.oracle.com/javase/7/docs/api/javax/xml/validation/package-summary.html - An implementation for W3C XML-Schema is provided with the JVM.
For RelaxNG, see these wrappers for Jing :