Results 1 to 4 of 4

Thread: Parsing Namespace Attributes from SOAPClient Response

  1. #1
    Join Date
    Jul 2009

    Parsing Namespace Attributes from SOAPClient Response

    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">
                    <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.

  2. #2
    Join Date
    Jul 2009

  3. #3
    Join Date
    Oct 2010
    The error is caused by looking for a plural version of discount, meanwhile the var_dump shows that its singular.
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  4. #4
    Join Date
    Sep 2013
    @swg1cor14 Did you found solution to your question? Getting xsi:type?
    I'm in similar situation, and really need to get xsi:type from response?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center