javaxmlxsdsaxonxml-validation

How to validate xml using external xsd with Saxon-HE java


I'm using Saxon-HE (11.3) for validating xml using external xsd. But I'm getting nullpointerexception as schemaManager is null.

Processor processor = new Processor (false); SchemaManager manager = processor.getSchemaManager(); manager.load(new StreamSource("xsdFile));

Getting NPE on 3rd line. I'm not getting why schemaManager is always null ? I tried to set new Processor(true) but it didn't work.


Solution

  • The Saxon documentation explains that

    1. new Processor(false) creates a non-schema-aware configuration

    2. new Processor(true) enables features such as schema processing that require a license key

    3. with a non-schema-aware configuration, processor.getSchemaManager() returns null.

    Possibly not the most elegant bit of API design, but the product is doing what the documentation says.