xml 如何在使用 SOAP 请求/响应进行验证时修复 soapenv:Envelope 问题在 XSD 架构中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24224226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix soapenv:Envelope issue in XSD schema while validating with SOAP request/response
提问by Anirban Sen Chowdhary
I have a SOAP request :-
我有一个 SOAP 请求:-
<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 响应:-
<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 :-
现在我的 XSD 架构是:-
<?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 :-
现在我的问题是每当我尝试针对此 XSD 架构验证我的 SOAP 请求时,我都会收到以下错误:-
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
请帮助......我需要知道我应该在我的 XSD 模式中修改什么,以便 SOAP 请求/响应根据 XSD 模式得到验证......因为我是新来的并尝试在整个互联网上搜索,所以我没有没有得到合适的答案...请帮忙
回答by helderdarocha
The SOAP request and response don't validate against yourschema, but the SOAP schema. You can use your XSD to validate your request and response if you importthe SOAP XSD into it:
SOAP 请求和响应不会针对您的架构进行验证,而是针对SOAP 架构进行验证。如果您将SOAP XSD导入其中,您可以使用 XSD 来验证您的请求和响应:
<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 instancedeclares a schemaLocationattribute mapping the namespaces of both schemas (yours and the SOAP schema) to their locations:
如果您的实例声明了一个schemaLocation将两个架构(您的架构和 SOAP 架构)的命名空间映射到它们的位置的属性,则您不必这样做:
<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>
回答by Marcin Erbel
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:
我的 Java 版本是:1.6.0_45。但是我通过下载 xsd 并将其作为文件导入来解决它:
<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="envelope.xsd" />
Maybe it will help somebody.
也许它会帮助某人。
回答by Anirban Sen Chowdhary
So, the final solution that worked for me is using import :-
因此,对我有用的最终解决方案是使用 import :-
<import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import>

