Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload