无需参考两个基于文件的xml和xsd文档即可验证任何语言的XML响应

时间:2018-07-08 18:46:08

标签: xml xslt soap xsd xml-parsing

我有一个SOAP xml响应。

我有一个xsd文件。

但是在SOAP xml响应的标头中是否有一种方法可以注入xsd模式文件的位置,并仅验证XMLDocument

这是我想出的,但是不起作用

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getCCMVersionResponse xmlns:ns="http://www.cisco.com/AXL/API/10.5"> 
<return><componentVersion>     
<version>10.5.2.11900(3)</version>
</componentVersion>
</return>
</ns:getCCMVersionResponse>
</soapenv:Body>
</soapenv:Envelope>

我正尝试更改标题

xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://test123a.epizy.com/getCCMVersion.xsd">

我尝试了schemaLocation,也尝试了file:///Users/me/Documents/getCCMVersion.xsd

有人可以帮忙吗?

这个家伙从来没有发呆

SOAP Response Schema Validation

1 个答案:

答案 0 :(得分:1)

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/   
http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getCCMVersionResponse xmlns:ns="http://www.cisco.com/AXL/API/10.5"                                                       
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                                              
xsi:schemaLocation="http://www.cisco.com/AXL/API/10.5  
/Users/michael/Downloads/axlsqltoolkit/schema/current/getCCMVersion.xsd">
<return>
<componentVersion>
<version>10.5.2.11900(3)</version>
</componentVersion>
</return>
</ns:getCCMVersionResponse>
</soapenv:Body>
</soapenv:Envelope>

证明这是正确的格式

但是您不能同时自我验证肥皂中的SOAP文档和XML。

您将需要转到     

如果xml响应或Soap Even lope已经声明了名称空间,则无法使用noNamespaceSchemaLocation。例如,xml响应已经具有

xmlns:ns="http://www.cisco.com/AXL/API/10.5"

所有尝试都是无奈的

<version>10.5.2.11900(3)</version>
</componentVersion>
</return>
</ns:getCCMVersionResponse>
</soapenv:Body>