Support #4878
closed
While validating a xml from multiple xsd (importing one another), sub part of xml gets validated successfully without regards of parent XSD
Fixed in Maintenance Release:
Description
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?
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.
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("http://schemas.xmlsoap.org/soap/envelope/", "Envelope");
sv.setDocumentElementName(qname);
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?
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
processor.getUnderlyingConfiguration().getEditionCode();
processor.getUnderlyingConfiguration().getClass().getName();
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.
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 -->
<!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>10.2</version>
</dependency>
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?
Sorry, schema validation requires a Saxon-EE license, and we have no plans to change that.
- Status changed from New to Closed
I think the questions have been answered, so I'm marking this as closed.
Please register to edit this issue
Also available in: Atom
PDF