xml – 如何修复soapenv:在使用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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇