Project

Profile

Help

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

Added by Juhi Gupta over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2021-01-15
Due date:
% Done:

0%

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

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?

Actions #1

Updated by Michael Kay over 3 years 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.

Actions #2

Updated by Juhi Gupta over 3 years 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("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?

Actions #3

Updated by Michael Kay over 3 years 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

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.

Actions #4

Updated by Juhi Gupta over 3 years 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 -->
		<!-- 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?

Actions #5

Updated by Michael Kay over 3 years ago

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

Actions #6

Updated by Michael Kay about 3 years ago

  • 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