在 XML 中获取 PHP Var_Dump 输出
Get PHP Var_Dump Output in XML
我正在使用 SoapClient return 来自 Web 服务提供商的数据。数据以典型的 object/array PHP 格式 returned。我想 return 它在 XML 中。
这是我调用 Web 服务的代码(我省略了我的用户名和密码):
<?php
//Calling Chrome ADS with Build Data
$client = new SoapClient('http://services.chromedata.com/Description/7b?wsdl');
$account = ['number'=>"", 'secret'=>"", 'country'=>"US", 'language'=>"en"];
$switch = ["ShowAvailableEquipment", "ShowExtendedTechnicalSpecifications", "ShowExtendedDescriptions"];
$vin = $_POST["b12"];
$result = $client->describeVehicle([
'accountInfo' => $account,
'switch' => $switch,
'vin' => $vin
]);
var_dump ($result);
?>
这是当前数据的输出方式:
object(stdClass)#2 (18) {
["responseStatus"]=>
object(stdClass)#3 (2) {
["responseCode"]=>
string(10) "Successful"
["description"]=>
string(10) "Successful"
}
["vinDescription"]=>
object(stdClass)#4 (11) {
["WorldManufacturerIdentifier"]=>
string(17) "Germany Audi Nsu "
["restraintTypes"]=>
array(5) {
[0]=>
object(stdClass)#5 (3) {
["group"]=>
object(stdClass)#6 (2) {
["_"]=>
string(6) "Safety"
["id"]=>
int(9)
}
["header"]=>
object(stdClass)#7 (2) {
["_"]=>
string(17) "Air Bag - Frontal"
["id"]=>
int(38)
}
["category"]=>
object(stdClass)#8 (2) {
["_"]=>
string(14) "Driver Air Bag"
["id"]=>
int(1001)
}
}
这是我希望数据输出的方式(这是我 运行 通过 SoapUI 请求时的结果):
<VehicleDescription country="US" language="en" modelYear="2008" bestMakeName="Audi" bestModelName="S4" bestStyleName="5dr Avant Wgn" xmlns="urn:description7b.services.chrome.com">
<responseStatus responseCode="Successful" description="Successful"/>
<vinDescription vin="WAUUL78E38A092113" modelYear="2008" division="Audi" modelName="S4" styleName="5dr Avant Wgn" bodyType="Wagon 4 Dr." drivingWheels="AWD" builddata="no">
<WorldManufacturerIdentifier>Germany Audi Nsu</WorldManufacturerIdentifier>
<restraintTypes>
<group id="9">Safety</group>
<header id="38">Air Bag - Frontal</header>
<category id="1001">Driver Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="38">Air Bag - Frontal</header>
<category id="1002">Passenger Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="39">Air Bag - Side</header>
<category id="1005">Front Side Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="39">Air Bag - Side</header>
<category id="1007">Front Head Air Bag</category>
</restraintTypes>
您可以使用__getLastResponse
Returns the XML received in the last SOAP response.
<?php
$client = 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
]);
//htmlentitites just to see the result in the browser window
echo "Response :<br/>", htmlentities($client->__getLastResponse()), "<br/>";
?>
我正在使用 SoapClient return 来自 Web 服务提供商的数据。数据以典型的 object/array PHP 格式 returned。我想 return 它在 XML 中。
这是我调用 Web 服务的代码(我省略了我的用户名和密码):
<?php
//Calling Chrome ADS with Build Data
$client = new SoapClient('http://services.chromedata.com/Description/7b?wsdl');
$account = ['number'=>"", 'secret'=>"", 'country'=>"US", 'language'=>"en"];
$switch = ["ShowAvailableEquipment", "ShowExtendedTechnicalSpecifications", "ShowExtendedDescriptions"];
$vin = $_POST["b12"];
$result = $client->describeVehicle([
'accountInfo' => $account,
'switch' => $switch,
'vin' => $vin
]);
var_dump ($result);
?>
这是当前数据的输出方式:
object(stdClass)#2 (18) {
["responseStatus"]=>
object(stdClass)#3 (2) {
["responseCode"]=>
string(10) "Successful"
["description"]=>
string(10) "Successful"
}
["vinDescription"]=>
object(stdClass)#4 (11) {
["WorldManufacturerIdentifier"]=>
string(17) "Germany Audi Nsu "
["restraintTypes"]=>
array(5) {
[0]=>
object(stdClass)#5 (3) {
["group"]=>
object(stdClass)#6 (2) {
["_"]=>
string(6) "Safety"
["id"]=>
int(9)
}
["header"]=>
object(stdClass)#7 (2) {
["_"]=>
string(17) "Air Bag - Frontal"
["id"]=>
int(38)
}
["category"]=>
object(stdClass)#8 (2) {
["_"]=>
string(14) "Driver Air Bag"
["id"]=>
int(1001)
}
}
这是我希望数据输出的方式(这是我 运行 通过 SoapUI 请求时的结果):
<VehicleDescription country="US" language="en" modelYear="2008" bestMakeName="Audi" bestModelName="S4" bestStyleName="5dr Avant Wgn" xmlns="urn:description7b.services.chrome.com">
<responseStatus responseCode="Successful" description="Successful"/>
<vinDescription vin="WAUUL78E38A092113" modelYear="2008" division="Audi" modelName="S4" styleName="5dr Avant Wgn" bodyType="Wagon 4 Dr." drivingWheels="AWD" builddata="no">
<WorldManufacturerIdentifier>Germany Audi Nsu</WorldManufacturerIdentifier>
<restraintTypes>
<group id="9">Safety</group>
<header id="38">Air Bag - Frontal</header>
<category id="1001">Driver Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="38">Air Bag - Frontal</header>
<category id="1002">Passenger Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="39">Air Bag - Side</header>
<category id="1005">Front Side Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="39">Air Bag - Side</header>
<category id="1007">Front Head Air Bag</category>
</restraintTypes>
您可以使用__getLastResponse
Returns the XML received in the last SOAP response.
<?php
$client = 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
]);
//htmlentitites just to see the result in the browser window
echo "Response :<br/>", htmlentities($client->__getLastResponse()), "<br/>";
?>