php - Soap 响应不是 XML 而是字符串
问题描述
我是一家法国公司的实习生,今天我开始从事一个 php SOAP 项目。
主要是从 SOAP 请求响应中获取数据。
请找到响应的 var_dump 值:
The\path\of\my\php\File.php:7:string '
--uuid:0fadab50-5d3c-4ee8-b58c-3a1bafca60e8
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:getVersionResponse xmlns:ns2="http://www.reseaux-et-canalisations.gouv.fr/ws2_2" xmlns:ns3="http://www.reseaux-et-canalisations.gouv.fr/schema-teleservice/2.2" xmlns:ns4="http://www.opengis.net/gml/3.2" xmlns:ns5="http://'... (length=934)
我正在努力获取这些数据,因为我得到的响应是字符串而不是 XML。
我尝试使用simplexml_load_string()
函数,但字符串转换根本不起作用。
我得到的是一个 SimpleXMLElement 对象。
我用它来只得到我感兴趣的东西:
$soapClient = new GUSoapClient();
$soapClient->getVersion("xml");
$lastResponse = $soapClient->getClient()->__last_response;
preg_match('/<soap:Envelope.*<\/soap:Envelope>/', $lastResponse, $output_array);
$xmlTxt = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".$output_array[0];
该函数getVersion()
返回SoapClient()->__getLastResponse();
.
在GUSoapClient()
中,该属性client
是私有的,所以我用getClient()
.
的值为$lastResponse
:
--uuid:ea2243f0-cb00-44ab-a9df-9a77d46febf8 Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"; Content-Transfer-Encoding: binary Content-ID: <root.message@cxf.apache.org> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:getVersionResponse xmlns:ns2="http://www.reseaux-et-canalisations.gouv.fr/ws2_2" xmlns:ns3="http://www.reseaux-et-canalisations.gouv.fr/schema-teleservice/2.2" xmlns:ns4="http://www.opengis.net/gml/3.2" xmlns:ns5="http://www.w3.org/1999/xlink" xmlns:ns6="http://www.isotc211.org/2005/gco" xmlns:ns7="http://www.isotc211.org/2005/gmd" xmlns:ns8="http://www.isotc211.org/2005/gts" xmlns:ns9="http://xml.insee.fr/schema"><version>4.3.3-SNAPSHOT</version><phase>1.0 1.1 1.2 2.0 2.1 2.2 2.3 3.1 3.2 3.3 5.1</phase><environment>recette</environment></ns2:getVersionResponse></soap:Body></soap:Envelope> --uuid:ea2243f0-cb00-44ab-a9df-9a77d46febf8--
的值为$output_array
:
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:getVersionResponse xmlns:ns2="http://www.reseaux-et-canalisations.gouv.fr/ws2_2" xmlns:ns3="http://www.reseaux-et-canalisations.gouv.fr/schema-teleservice/2.2" xmlns:ns4="http://www.opengis.net/gml/3.2" xmlns:ns5="http://www.w3.org/1999/xlink" xmlns:ns6="http://www.isotc211.org/2005/gco" xmlns:ns7="http://www.isotc211.org/2005/gmd" xmlns:ns8="http://www.isotc211.org/2005/gts" xmlns:ns9="http://xml.insee.fr/schema"><version>4.3.3-SNAPSHOT</version><phase>1.0 1.1 1.2 2.0 2.1 2.2 2.3 3.1 3.2 3.3 5.1</phase><environment>recette</environment></ns2:getVersionResponse></soap:Body></soap:Envelope>
我试图这样做:
$xml = simplexml_load_string($xmlTxt);
但是var_dump($xml)
给我这个:
object(SimpleXMLElement)[5]
我想要的只是得到我想要的价值。如果您对我做错了什么有任何想法,我想听听他们的意见。谢谢 !
注意:我是法国人,我的英语并不完美。如果我不清楚,请告诉我;)
解决方案
尝试echo
而不是var_dump
SimpleXMLElements 有一个__toString()
方法,这意味着如果您尝试回显它,即使它是一个对象,它也会为您转换为字符串。http://php.net/manual/fr/simplexmlelement.tostring.php
推荐阅读
- java - 使用 spring boot 和 postgres 的休眠 oneToMany 问题
- r - makeClusterPSOCK ERROR 工作人员无法连接
- angular - 我们如何防止this.debug is not a function导致编译器退出
- assembly - 这些变量之间的依赖关系是什么?
- docker-compose - 从一个容器到另一个容器进行 API 调用
- javascript - Javascript 导航菜单闪烁
- three.js - 在threejs中渲染透明瓶子
- javascript - 发布请求上的 XMLHttpRequest 导致 isTrusted:false (419)
- flutter - 如何使用 Google Play 应用程序登录更新 Facebook 哈希
- javascript - 使用 Mongoosastic 更新 MongoDB 文档后的 Elasticsearch 同步/更新