![](/img/trans.png)
[英]XML - XSD validation error: No matching global declaration available for the validation root
[英]Envelope': No matching global declaration available for the validation root error when validating SOAP response in php
我試圖驗證肥皂響應信封但不斷收到錯誤
我有我無法更改的肥皂響應(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 Document 驗證對 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
任何人都可以對我如何解決這個錯誤提出一些見解嗎?
這是一個聲明問題。 在 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 發布的定義上的流量過多。 w3c 對定義請求設置了延遲。 為避免這些延遲,您可以將定義保存到本地文件並改為使用它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.