duanrenzou1619 2018-09-20 18:38
浏览 156
已采纳

Soap XML输出创建一个数组

I am calling a web service using SoapClient and attempting to pull data from the response output. I have modified the Soap response so that it displays in XML.

I did so by writing this: $resultxml = htmlentities($client->__getLastResponse()) . " ";.

If you do a simple print_r($resultxml); you receive the full output, obviously.

What I am having trouble with is using DomDocument with $resultxml to create my techData array. If I copy and paste the Soap output and create a stand-alone XML file with it, then add it to $dom->loadXML(); the techData array is created perfectly. However, when I try to pull the XML from $resultxml I receive a blank array.

Any ideas as to why this is? Should I consider revising $resultxml = htmlentities($client->__getLastResponse()) . " ";? Am I calling it incorrectly?

Thanks so much.

My PHP with my SoapClient request and array code:

<?php
 $client = new SoapClient('http://services.chromedata.com/Description/7b?wsdl', array('trace' => 1));
 $account = ['number'=>"", 'secret'=>"", 'country'=>"US",    'language'=>"en"];
 $switch =  ["ShowAvailableEquipment", "ShowExtendedTechnicalSpecifications", "ShowExtendedDescriptions"];
 $vin = $_POST["b12"];

$result = $client->describeVehicle([
'accountInfo' => $account,
'switch' => $switch,
'vin' => $vin
]);

$resultxml = htmlentities($client->__getLastResponse()) . "
";

$dom = new DOMDocument();
$dom->loadXML($resultxml);


$techData = [];
foreach ( $dom->getElementsByTagName('technicalSpecification') as $techSpec )   {
$id = $techSpec->getElementsByTagName('titleId')->item(0)->nodeValue;
$techData [$id]= $techSpec->getElementsByTagName('value')->item(0)->getAttribute("value")."<br>";

}

print_r($techData);
echo "<br>";
  • 写回答

1条回答 默认 最新

  • drwjv28028 2018-09-20 19:20
    关注

    When you use htmlentities() - this will encode the markup, so

    <S:Body>
    

    becomes

    &lt;S:Body&gt;
    

    thiw ill not work if you then try to load it as an XML document, so just use

    $resultxml = $client->__getLastResponse();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)