2018-09-20 18:38
浏览 142

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:

 $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();

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


echo "<br>";
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drwjv28028 2018-09-20 19:20

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




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

    $resultxml = $client->__getLastResponse();
    解决 无用
    打赏 举报