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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵