Support #4878

While validating a xml from multiple xsd (importing one another), sub part of xml gets validated successfully without regards of parent XSD

Added by Juhi Gupta about 1 month ago. Updated about 1 month ago.

Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:


We have schemas defined by multiple xsd files, for example : xsd1: soapenvelope.xsd and xsd2: mainBody.xsd. where soapenvelope.xsd contains the main element (soap envelope) and then imports the xsd2 for inner elements.

We always need to validate against the main element, but when we only receive inner element it passes the validation also.

Is it possible to specify the element with which the payload should be validated against?


#1 Updated by Michael Kay about 1 month ago

Yes, you can specify the top level element for validation. The details depend on how you are running the validator.

With the command line interface, use the -top option, e.g -top:{http://my.payload.uri}root or -top:{http://the-soap-namespace/}envelope

With the s9api SchemaValidator, call setDocumentElementName().

I don't think it can be done using the JAXP validation API.

#2 Updated by Juhi Gupta about 1 month ago

We tried to change our code, we were using javax.xml.validation.Validator; with SchemaFactory to the suggested net.sf.saxon.s9api.SchemaValidator;

Our code now looks like this:

                Processor proc = new Processor(true);
                SchemaManager sm = proc.getSchemaManager();
                sm.load(new StreamSource(new File("soapenvelope.xsd")));
                SchemaValidator sv = sm.newSchemaValidator();
                QName qname = new QName("", "Envelope");
                sv.validate(new StreamSource(new StringReader(xmlPath)));

but now we are having following error:

21-01-15 10:53:23.322  INFO 1 --- [nio-8080-exec-1] com.comp.Validator       : Performing input validation on requestpayload 
java.lang.NullPointerException: Cannot invoke "net.sf.saxon.s9api.SchemaManager.load(javax.xml.transform.Source)" because "sm" is null

Can you provide some code sample for this implementation to guide us the change?

#3 Updated by Michael Kay about 1 month ago

If getSchemaManager() returns null, it's because for some reason you've created a Saxon configuration that doesn't support schema processing. Try (for diagnostics) printing


Given that you called new Processor(true), the most likely explanations are either (a) you picked up Saxon-HE off the classpath, or (b) some problem with finding your license file.

#4 Updated by Juhi Gupta about 1 month ago

We added the print statements, it printed the following details:

proc.getUnderlyingConfiguration().getEditionCode(): HE
proc.getUnderlyingConfiguration().getClass().getName(): net.sf.saxon.Configuration

In out pom we have added following saxon jar

        <!-- Required for xml transfomation -->
                <!-- -->

Then we found that Saxon HE does not support this feature, its part of Saxon EE supports it. We wanted to know if there is any roadmap for this support in HE, or any other workaround we can use?

#5 Updated by Michael Kay about 1 month ago

Sorry, schema validation requires a Saxon-EE license, and we have no plans to change that.

Please register to edit this issue

Also available in: Atom PDF