Reputation: 8321
I have a SOAP request :-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://services.test.com/schema/MainData/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:retrieveDataRequest>
<v1:Id>58</v1:Id>
</v1:retrieveDataRequest>
</soapenv:Body>
</soapenv:Envelope>
and a SOAP response :-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<retrieveDataResponse xmlns="http://services.test.com/schema/MainData/V1">
<Response>The Data retrieved from the Database</Response>
<Id>58</Id>
<Name>fdfdf</Name>
<Age>44</Age>
<Designation>sse</Designation>
</retrieveDataResponse>
</soap:Body>
</soap:Envelope>
Now my XSD schema is :-
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://services.test.com/schema/MainData/V1"
xmlns:tns="http://services.test.com/schema/MainData/V1" elementFormDefault="qualified">
<complexType name="dataRequest">
<sequence>
<element name="Id" type="int"></element>
<element name="Name" type="string"></element>
<element name="Age" type="int"></element>
<element name="Designation" type="string"></element>
</sequence>
</complexType>
<complexType name="dataResponse">
<sequence>
<element name="Response" type="string"></element>
<element name="Id" type="int"></element>
<element name="Name" type="string"></element>
<element name="Age" type="int"></element>
<element name="Designation" type="string"></element>
</sequence>
</complexType>
<element name="insertDataRequest" type="tns:dataRequest"></element>
<element name="insertDataResponse" type="tns:dataResponse"></element>
<element name="retrieveDataRequest" type="tns:retrieveRequest"></element>
<element name="retrieveDataResponse" type="tns:dataResponse"></element>
<complexType name="retrieveRequest">
<sequence>
<element name="Id" type="int"></element>
</sequence>
</complexType>
<element name="updateDataRequest" type="tns:dataRequest"></element>
<element name="updateDataRespone" type="tns:dataResponse"></element>
<complexType name="deleteRequest">
<sequence>
<element name="ID" type="int"></element>
</sequence>
</complexType>
<element name="deleteDataRequest" type="tns:deleteRequest"></element>
<element name="deleteDataResponse" type="tns:dataResponse"></element>
</schema>
Now my issue is whenever I try to validate my SOAP request against this XSD schema , I get the following error :-
Not valid.
Error - Line 1, 133: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 133; cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.
Please help ... I need to know what should I modify in my XSD schema so that the SOAP request/response gets validate against the XSD schema ... Since I am new in this and tried searching all over the internet, I didn't get suitable answer ... Please help
Upvotes: 11
Views: 59472
Reputation: 8321
So, the final solution that worked for me is using import :-
<import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import>
Upvotes: 1
Reputation: 1643
I had the same problem and for me schema import didn't work. Stack:
10:18:03,206 | DEBUG | iEsb | DefaultValidationErrorHandler | | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Validation error: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:233)[:]
My java version was: 1.6.0_45. But I solved it through downloading xsd and importing it as a file:
<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="envelope.xsd" />
Maybe it will help somebody.
Upvotes: 3
Reputation: 23627
The SOAP request and response don't validate against your schema, but the SOAP schema. You can use your XSD to validate your request and response if you import the SOAP XSD into it:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://services.test.com/schema/MainData/V1"
xmlns:tns="http://services.test.com/schema/MainData/V1" elementFormDefault="qualified">
<import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import>
...
You don't have to do that if your instance declares a schemaLocation
attribute mapping the namespaces of both schemas (yours and the SOAP schema) to their locations:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://services.test.com/schema/MainData/V1 your-schema.xsd
http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<retrieveDataResponse xmlns="http://services.test.com/schema/MainData/V1">
<Response>The Data retrieved from the Database</Response>
<Id>58</Id>
<Name>fdfdf</Name>
<Age>44</Age>
<Designation>sse</Designation>
</retrieveDataResponse>
</soap:Body>
</soap:Envelope>
Upvotes: 12