Reputation: 799
I'm getting a response as the below from the public WSDL http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL
How can I get the sISOCodein to a php variable?
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:CountryCurrencyResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo">
<m:CountryCurrencyResult>
<m:sISOCode>INR</m:sISOCode>
<m:sName>Rupees</m:sName>
</m:CountryCurrencyResult>
</m:CountryCurrencyResponse>
</soap:Body>
</soap:Envelope>
I have written the code as below
$wsdl = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL";
$client = new SoapClient($wsdl, array('trace'=>1)); // The trace param will show you errors stack
// web service input params
$request_param = array("sCountryISOCode" => "IN");
$responce_param = null;
try
{
$responce_param = $client->CountryCurrency($request_param);
$xml = simplexml_load_string($responce_param);
foreach ($xml->xpath('//CountryCurrencyResult') as $item)
{
print_r($item);
}
}
catch (Exception $e)
{
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
How can I get the Parse the response and get the values in to the variables?
Upvotes: 1
Views: 958
Reputation: 4962
The result is a stdClass
object. Just try this.
$wsdl = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL";
$client = new SoapClient($wsdl, array('trace' => 1)); // The trace param will show you errors stack
// web service input params
$request_param = array('sCountryISOCode' => 'IN');
$responce_param = null;
try {
$responce_param = $client->CountryCurrency($request_param);
print_r($responce_param->CountryCurrencyResult->sISOCode);
} catch (Exception $e) {
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
Upvotes: 3