OK so I have SOAPClient making a call. If I use __getLastResponse() I get a line in my XML like this:
<Discount xsi:type="ProgressivePromotion" from="2013-05-05T00:00:00" to="2013-05-14T00:00:00" type="Percent" value="20" name="Special Deal"/>
However, the function in my SOAPClient Class returns an object.
The code for the call in the PHP class is:
function SearchHotels($parameters ){
$funcRet = null;
try {
$funcRet = $this->client->SearchHotels($parameters);
} catch ( Exception $e ) {
echo "(SearchHotels) SOAP Error:\n-------------------------------------\n" . $e->getMessage () . "\n\n";
echo "(SearchHotels) Request:\n-------------------------------------\n" . $this->client->__getLastRequest() . "\n\n";
echo "(SearchHotels) Response:\n-------------------------------------\n" . $this->client->__getLastResponse() . "\n\n";
}
return $funcRet;
}
When I use the object that is returned, I can access the following attributes from the Discount element as:
type: ProgressivePromotion from: 2013-05-05T00:00:00 to: 2013-05-14T00:00:00 value: 20 name: Special Deal
But I can't access type="Percent"
It seems that SOAPClient disregards the xsi namespace in xsi:type and just stores that attribute as type.
So how can I access xsi:type AND type so I can tell if my discount is a Percent or Amount or whatever other type it could be?
at the top of my SOAP Response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SearchHotelsResponse xmlns="http://tourico.com/webservices/hotelv3">
<SearchHotelsResult>
<Info xmlns="http://schemas.tourico.com/webservices/hotelv3" version="9.71" culture="en-US" serverTime="2013-02-06T14:49:58.3500117-05:00"/>
<HotelList xmlns="http://schemas.tourico.com/webservices/hotelv3">
If I var_dump the object returned, I get
stdClass Object
(
[SearchHotelsResult] => stdClass Object
(
[Info] => stdClass Object
(
[version] => 9.71
[culture] => en-US
[serverTime] => 2013-02-06T15:17:59.8445748-05:00
)
[HotelList] => stdClass Object
(
[Hotel] => Array
(
[0] => stdClass Object
[RoomTypes] => stdClass Object
(
[RoomType] => Array
(
[0] => stdClass Object
(
[Discount] => stdClass Object
(
[from] => 2013-05-05T00:00:00
[to] => 2013-05-14T00:00:00
[type] => ProgressivePromotion
[value] => 20
[name] => Special Deal
)
See how I lost the type="Amount"?
I can't call Discounts by doing
echo $result->SearchHotelsResult->HotelList->Hotel[0]->RoomTypes->RoomType[0]->Discounts->type;
Because I get
Undefined property: stdClass::$Discounts Notice: Trying to get property of non-object
So I convert the whole object into a giant multidimensional array and access things that way. Regardless, the type="Amount" isnt being pulled.