Cvc-elt.1:找不到元素“soap:Envelope"的声明 [英] Cvc-elt.1: Cannot Find The Declaration Of Element 'soap:Envelope'

查看:45
本文介绍了Cvc-elt.1:找不到元素“soap:Envelope"的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我将 XSD 用于 SOAP XML,但是当我在 FREEFORMATTER.COM,我收到此错误:

Currently I'm using XSD for SOAP XML, but when I run my SOAP XML and XSD on FREEFORMATTER.COM, I get this error:

Cvc-elt.1:找不到元素soap:Envelope"的声明..1"行,170"列

Cvc-elt.1: Cannot Find The Declaration Of Element 'soap:Envelope'.. Line '1', Column '170'

这是我的 SOAP XML:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Cancel_OrderLine xmlns="http://tempuri.org/">
      <Data>
        <Delivery>
          <Delivery_No>1605000194</Delivery_No>
          <Reason>qwertyu</Reason>
        </Delivery>
        <Delivery>
          <Delivery_No>1605000194</Delivery_No>
          <Reason>qwerty</Reason>
        </Delivery>
      </Data>
    </Cancel_OrderLine>
  </soap:Body>
</soap:Envelope>

这是我的 XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <xs:element name="Cancel_OrderLineReq">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Data">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Delivery" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:int" name="Delivery_No"/>
                    <xs:element type="xs:string" name="Reason"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

我应该怎么做才能消除错误?

What should I do to eliminate the error?

推荐答案

首先,您必须将 targetNamespace="http://tempuri.org/" 添加到 xs:schema XSD 元素,以便 XSD 应用于 XML 负载中使用的命名空间.

First, you must add a targetNamespace="http://tempuri.org/" to the xs:schema element of your XSD in order for your XSD to apply to the namespace used in your XML payload.

然后您可以采用以下任一方法:更改 XML更改 XSD.根据您控制的文件进行选择.

Then you can take either of the following approaches: Change the XML or Change the XSD. Choose according to which files you control.

添加

xsi:schemaLocation="http://tempuri.org/ tempuri.xsd
                    http://schemas.xmlsoap.org/soap/envelope/ 
                    http://schemas.xmlsoap.org/soap/envelope/

soap:Envelope:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xsi:schemaLocation="http://tempuri.org/ tempuri.xsd
                                   http://schemas.xmlsoap.org/soap/envelope/ 
                                   http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Cancel_OrderLine xmlns="http://tempuri.org/">
      <Data>
        <Delivery>
          <Delivery_No>1605000194</Delivery_No>
          <Reason>qwertyu</Reason>
        </Delivery>
        <Delivery>
          <Delivery_No>1605000194</Delivery_No>
          <Reason>qwerty</Reason>
        </Delivery>
      </Data>
    </Cancel_OrderLine>
  </soap:Body>
</soap:Envelope>

更改 XSD

添加

<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"   
           schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>

到 XSD 的 xs:schema 元素:

to the xs:schema element of your XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
           targetNamespace="http://tempuri.org/">

  <xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"   
             schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>

  <xs:element name="Cancel_OrderLineReq">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Data">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Delivery" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:int" name="Delivery_No"/>
                    <xs:element type="xs:string" name="Reason"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

这两种方法都可以成功验证您的 SOAP 信封及其有效负载.

这篇关于Cvc-elt.1:找不到元素“soap:Envelope"的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆