繁体   English   中英

肥皂响应不是XML,而是字符串

[英]Soap Response not XML but String

我是一家法国公司的实习生,今天我开始从事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具有__toString()方法,这意味着即使您尝试将其作为对象,它也会为您转换为字符串。 http://php.net/manual/fr/simplexmlelement.tostring.php

如果simple_xml必须处理名称空间前缀,我会遇到一些困难。

尝试删除

$clean_xml = str_ireplace(['SOAP-ENV:', 'SOAP:', 'ns2:'], '', $xml);

$xmlArray = simplexml_load_string($clean_xml);

$json = json_encode($xmlArray);
$array = json_decode($json,TRUE);

$value = $array['foo']['bar'];

$ array应该包含SOAP结果作为数组

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM