xml - 如何修复 soapenv :Envelope issue in XSD schema while validating with SOAP request/response

标签 xml validation soap xsd

我有一个 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>

和 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>

现在我的 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>

现在我的问题是每当我尝试根据此 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'.

请帮助...我需要知道我应该在我的 XSD 架构中修改什么,以便 SOAP 请求/响应针对 XSD 架构进行验证...因为我是新手并尝试在整个互联网上搜索,我没有得到合适的答案......请帮忙

最佳答案

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>

...

如果您的实例声明了一个 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>

关于xml - 如何修复 soapenv :Envelope issue in XSD schema while validating with SOAP request/response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24224226/

相关文章:

android - 如何在 Android 中以编程方式创建菜单?

validation - 在 Zend 框架 2 中验证日期

validation - 导致 "Expression has changed after it was checked"异常的 FormBuilder 控件

java - 将 XML 文件传递​​到 Web 服务

java - 如何让 Axis 1.4 不为同一个 XML namespace 生成多个前缀?

java - startActivity()期间的"Application was stopped"

ruby - 以与多个选择参数相同的顺序对 XPath 进行排序

c# - 修复 "Improper Restriction of xml external entity reference"的最佳方法是什么?

validation - 序列化 dojox.validation.check 配置文件对象

c# - 如何强制 C# Web 服务对象属性中的最大字符串长度?