使用PHP解析soap响应 [英] Parse soap response using PHP

查看:181
本文介绍了使用PHP解析soap响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从下面的soap响应中获取所有元素和值作为数组.但是我只得到元素而没有值.

I am trying to get all the elements and values as array from the below soap response. But I am only getting elements but no values.

我已使用此解析器获取元素和值.预先感谢.

I have used this parser to get the elements and values. Thanks in advance.

这是我正在使用的代码,

Here is the code I am using,

  $response = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <toy:SearchReq xmlns:toy="www.something.com/toy" xmlns:gen="www.something.com/gen">
         <gen: manufacturedIn="SomePlace"/>
         <toy:SearchToy>
            <toy:SearchType>
               <gen:Shop Code="WALMART"/>
            </toy:SearchType>    
         </toy:SearchToy>
         <toy:SearchToy>
            <toy:SearchType>
               <gen:Shop Code="AMAZON"/>
            </toy:SearchType>    
         </toy:SearchToy>
      </toy:SearchReq>
   </soapenv:Body>
</soapenv:Envelope>';

$doc = simplexml_load_string($response);

$path = array($doc
    ->children('http://schemas.xmlsoap.org/soap/envelope/')
    ->Body
    ->children('www.something.com/toy'));


foreach($path as $elem){
    print_r($elem);
    $elemChild = $elem->children('www.something.com/gen');
    var_dump($elemChild);
}

推荐答案

在此处查看完整参考: https://stackoverflow.com/a/38783380/6511851

See complete reference here: https://stackoverflow.com/a/38783380/6511851

$sxe = new SimpleXMLElement($response); //in $response variable it's an XML file or response
$sxe->registerXPathNamespace('d', 'urn:schemas-microsoft-com:xml-diffgram-v1');
$result = $sxe->xpath("//NewDataSet");

echo "<pre>";
foreach ($result[0] as $title) {
    print_r($title);
}

有关更多信息,请访问网站: https://vaja906programmingworld.wordpress.com/

For more information visit site: https://vaja906programmingworld.wordpress.com/

这篇关于使用PHP解析soap响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆