0

I have a number of required soap headers defined in XSDs that I am not allowed to change, as existing clients are already using these in production.

In one of these schemas there are a number of imports with the same namespace value. When I attempt loading this schema into my validation interceptor I get an exception saying that the sdsd:SystemName (2nd element in the sequence) is undefined. If I open the XSD in IntelliJ Idea 13 I get red markings for sdsd:SystemName and the rest of the list of elements. Only the sdsd:SystemOwnerName is found and loaded.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:sdsd="http://www.sdsd.dk/dgws/2010/08" xmlns:sdsd201206="http://www.sdsd.dk/dgws/2012/06" targetNamespace="http://www.sdsd.dk/dgws/2012/06" elementFormDefault="qualified" attributeFormDefault="unqualified">
<import namespace="http://www.sdsd.dk/dgws/2010/08" schemaLocation="../../2010/08/SystemOwnerName.xsd" />
<import namespace="http://www.sdsd.dk/dgws/2010/08" schemaLocation="../../2010/08/SystemName.xsd" />
<import namespace="http://www.sdsd.dk/dgws/2010/08" schemaLocation="../../2010/08/SystemVersion.xsd" />
<import namespace="http://www.sdsd.dk/dgws/2010/08" schemaLocation="../../2010/08/OrgResponsibleName.xsd" />
<import namespace="http://www.sdsd.dk/dgws/2010/08" schemaLocation="../../2010/08/OrgUsingName.xsd" />
<import namespace="http://www.sdsd.dk/dgws/2010/08" schemaLocation="../../2010/08/OrgUsingID.xsd" />
<import namespace="http://www.sdsd.dk/dgws/2010/08" schemaLocation="../../2010/08/RequestedRole.xsd" />

<element name="WhitelistingHeader" type="sdsd201206:WhitelistingHeader">
    <annotation>
        <documentation xml:lang="en-GB">SDSD Whitelisting header.</documentation>
        <documentation xml:lang="da-DK">SDSD Whitelisting header.</documentation>
    </annotation>
</element>
<complexType name="WhitelistingHeader">
    <sequence>
       <element ref="sdsd:SystemOwnerName" minOccurs="1" maxOccurs="1" />
       <element ref="sdsd:SystemName" minOccurs="1" maxOccurs="1" />
       <element ref="sdsd:SystemVersion" minOccurs="1" maxOccurs="1" />
       <element ref="sdsd:OrgResponsibleName" minOccurs="1" maxOccurs="1" />
       <element ref="sdsd:OrgUsingName" minOccurs="1" maxOccurs="1" />
       <element ref="sdsd:OrgUsingID" minOccurs="1" maxOccurs="1" />
       <element ref="sdsd:RequestedRole" minOccurs="1" maxOccurs="1" />
    </sequence>
</complexType>

`

I have read this thread One xml namespace equals one and only one schema file? and can confirm that if I make a new 'master' schema that includes the schemas that are imported in the schema shown above and then change the imports in the schema shown above to a single include of the 'master' schema my Spring-ws validation interceptor is working correctly.

However since changing the schema is not an option I am looking for other options.

I have found Xerces documentation and Validate XML with loading schemas at runtime, failure depending on schema order suggesting that I can set the feature "http://apache.org/xml/features/validation/schema/handle-multiple-imports" to true on the XmlSchemaFactory in order to make Xerces not fail when validating a schema with multiple imports to the same namespace. However I have my own SoapHeaderValidatingInterceptor that extends the AbstractValidatingInterceptor, which in turn uses the Spring WS internal XmlValidatorFactory to create the XmlValidator that is used to validate the XSDs.

Any tips as to how I can enable the handle-multiple-imports feature will be greatly appreciated.

Community
  • 1
  • 1
joensson
  • 1,967
  • 1
  • 22
  • 18
  • You say you cannot write a new schema document that does all the includes because "changing the schema is not an option" -- but in what sense does a new schema document "change the schema"? All the existing schema documents are completely untouched and unchanged. – C. M. Sperberg-McQueen Jun 18 '14 at 13:33
  • I realize that XML wise the result using the modified schema is the same and as far as validation is concerned the end result is perfectly valid. However if I create a modified WhitelistingHeader schema then my dev team will have to maintain that file and keep it in sync with any changes made to the original WhitelistingHeader schema we receive from our customer. Changes are not frequent but if possible we would really like to avoid having a locally modified schema just for this purpose. It is the solution we are currently using - but if possible we would like to use the schema delivered to us – joensson Jun 19 '14 at 10:06
  • You seem to be using the word "schema" to mean "schema document" and the word "modified" to mean "newly created"; this makes it hard for me to be confident that I understand what you mean. Good luck. – C. M. Sperberg-McQueen Jun 19 '14 at 14:41

0 Answers0