Forum Discussion

Narmin's avatar
Narmin
Occasional Visitor
7 years ago

Cannot find the declaration of element 'S:Envelope'

I realize that this question has been asked many times  but none of posted solutions helped me either :(

 

So I  need to validate soap response against xsd schema using groovy script.  Here is my xsd schema:

 

<!--
Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<xs:schema
xmlns:tns="http://localhost:8888/ws/UserData"
version="1.0" targetNamespace="http://localhost:8888/ws/UserData"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ "/>
<xs:element name="getAllUsers" type="tns:getAllUsers"/>
<xs:element name="getAllUsersResponse" type="tns:getAllUsersResponse"/>
<xs:element name="getUserSalary" type="tns:getUserSalary"/>
<xs:element name="getUserSalaryResponse" type="tns:getUserSalaryResponse"/>
<xs:element name="setUsersalary" type="tns:setUsersalary"/>
<xs:element name="setUsersalaryResponse" type="tns:setUsersalaryResponse"/>
<xs:complexType name="getUserSalary">
<xs:sequence>
<xs:element name="arg0" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getUserSalaryResponse">
<xs:sequence>
<xs:element name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getAllUsers">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="getAllUsersResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="setUsersalary">
<xs:sequence>
<xs:element name="arg0" type="xs:int"/>
<xs:element name="arg1" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="setUsersalaryResponse">
<xs:sequence/>
</xs:complexType>
</xs:schema>

 

Here is the Soap request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:user="http://localhost:8888/ws/UserData">
<soapenv:Header/>
<soapenv:Body>
<user:getUserSalary>
<arg0>1</arg0>
</user:getUserSalary>
</soapenv:Body>
</soapenv:Envelope> 

 

 

And Soap Response:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getUserSalaryResponse xmlns:ns2="http://localhost:8888/ws/UserData">
<return>2000</return>
</ns2:getUserSalaryResponse>
</S:Body>
</S:Envelope>

 


And my groovy script for validation:

 

import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory

String response = context.expand('${SOAP Request1#Response}')
log.info(response)
new File( "C:\\Path\\to\\myschemafile.xsd" ).withReader { xsd ->
SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI )
.newSchema( new StreamSource( xsd ) )
.newValidator()
.validate( new StreamSource( new StringReader( response ) ) )

}

 

Any help appreciated as I got stuck right here.

Regards.