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()) . "\n";
.
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()) . "\n";
? 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()) . "\n";
$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>";
When you use htmlentities()
- this will encode the markup, so
<S:Body>
becomes
<S:Body>
thiw ill not work if you then try to load it as an XML document, so just use
$resultxml = $client->__getLastResponse();