【问题标题】:Envelope': No matching global declaration available for the validation root error when validating SOAP response in phpEnvelope':在 php 中验证 SOAP 响应时,没有可用于验证根错误的匹配全局声明
【发布时间】:2019-06-15 23:05:31
【问题描述】:

我正在尝试验证一个肥皂响应信封,但不断收到错误

我有这个我无法更改的肥皂响应 (response.xml)

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <GetVehicleMakesResponse xmlns="http://api.examle.com/">
        <GetVehicleMakesResult>
            <VehicleMakes xmlns="">
                <VehicleMake>
                    <MakeID>37</MakeID>
                    <MakeName>ALFA ROMEO</MakeName>
                </VehicleMake>
                <VehicleMake>
                    <MakeID>3</MakeID>
                    <MakeName>AUDI</MakeName>
                </VehicleMake>
                <VehicleMake>
                    <MakeID>19</MakeID>
                    <MakeName>BMW</MakeName>
                </VehicleMake>
            </VehicleMakes>
        </GetVehicleMakesResult>
    </GetVehicleMakesResponse>
</soap:Body>

我有一个 XSD 文件来验证这一点 (GetVehicleMakes.xsd)

<xs:schema xmlns:tns="http://api.examle.com/" attributeFormDefault="unqualified" elementFormDefault="qualified" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
  <xs:element name="GetVehicleMakesResponse">
        <xs:complexType>
              <xs:sequence>
                    <xs:element name="GetVehicleMakesResult">
                          <xs:complexType>
                                <xs:sequence>
                                      <xs:element name="VehicleMakes">
                                            <xs:complexType>
                                                  <xs:sequence>
                                                        <xs:element maxOccurs="unbounded" name="VehicleMake">
                                                              <xs:complexType>
                                                                    <xs:sequence>
                                                                          <xs:element name="MakeID" type="xs:unsignedByte" />
                                                                          <xs:element name="MakeName" type="xs:string" />
                                                                    </xs:sequence>
                                                              </xs:complexType>
                                                        </xs:element>
                                                  </xs:sequence>
                                            </xs:complexType>
                                      </xs:element>
                                </xs:sequence>
                          </xs:complexType>
                    </xs:element>
              </xs:sequence>
        </xs:complexType>
  </xs:element>

当我使用 PHP DOM 文档验证对 XSD 的响应时

$xml = new DOMDocument(); 
$xml->load('response.xml');
$xml->schemaValidate('GetVehicleMakes.xsd')

我收到以下错误

Error 1845: Element '{http://www.w3.org/2003/05/soap-envelope}Envelope': No matching global declaration available for the validation root. in file:/P:/xampp/htdocs/test/response.xml on line 1

谁能提供一些关于我如何解决此错误的见解?

【问题讨论】:

    标签: php soap domdocument xsd-validation


    【解决方案1】:

    这是一个声明问题。在 xml 响应中,soap 信封元素的命名空间与 xsd 文件中定义的命名空间不同。

    在xsd文件中定义如下:

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

    但是响应中的soap信封元素是用命名空间http://www.w3.org/2003/05/soap-envelope定义的。正如您的错误消息所说,针对 xsd 的验证不知道信封元素的这个特定命名空间。

    由于您无法更改soap 响应,因此您必须编辑xsd 文件。只需导入正确的信封定义即可。

    <xs:import namespace="http://www.w3.org/2003/05/soap-envelope" schemaLocation="http://www.w3.org/2003/05/soap-envelope"/>
    

    您可能会意识到,验证会持续几秒钟。这是很正常的,因为 w3c 发布的定义中有excessive traffic。 w3c 对定义请求设置了延迟。为避免这些延迟,您可以将定义保存到本地文件并改用它们。

    【讨论】:

      猜你喜欢
      • 2012-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 2012-01-15
      • 1970-01-01
      相关资源
      最近更新 更多