views:

38

answers:

1

I'm basically trying to merge multiple SOAP responses because the web service only supports one room lookup at a time instead of multiple as far as I know - its the CheckAvailability method and using this WSDL

If I supply my credentials, arrival/departure dates in my SOAP request I get the following data back, which is mainly compromised of 3 things.. Room Types ( type of room and description ), Rate Plans ( deals ) and Room Rates ( maps rooms with plans/deals ).

Let's say the user specifies an arrival date of February 20th and a departure date of February 24th 2010, the arrival/departure but would like to book 3 rooms:

  • 1x Room with 3x adults 2x children
  • 1x Room with 2x adults 1x children
  • 1x Room with 1x adult 0 children

So since we have 3 rooms it has to be 3 requests, because the # of people differ the prices will change.

My main concern is how to merge these such that I can display the room types first in my web page, and within each room type block display the price for each room the user would like, ex:

<li>
    <h2>King Suite</h2>
    <h3>Prices</h3>
    <ul class="tabs">
      <li>Room 1<table></table></li>
      <li>Room 2<table></table></li>
      <li>Room 3<table></table></li>
    </ul>
</li>

An example of the SOAP response:

        <RoomStays>
            <RoomStay>
                <RoomTypes>
                    <RoomType RoomTypeCode="KING" NumberOfUnits="14">
                        <RoomDescription Name="Kings Room">
                            <Text>Content</Text>
                            <Image>http://static.images.com/file.gif&lt;/Image&gt;
                        </RoomDescription>
                    </RoomType>
                </RoomTypes>
                <RatePlans>
                    <RatePlan RatePlanCode="SPECIAL" RatePlanName="Special Rate">
                        <RatePlanDescription Name="Published Rate">
                            <Text>Published Rate European Plan</Text>
                        </RatePlanDescription>
                        <Guarantee>
                            <GuaranteeDescription>
                                <Text>1 night room and tax due at the time of reservation</Text>
                            </GuaranteeDescription>
                        </Guarantee>
                        <CancelPenalties>
                            <CancelPenalty>
                                <PenaltyDescription>
                                    <Text>30 day cancellation policy</Text>
                                </PenaltyDescription>
                            </CancelPenalty>
                        </CancelPenalties>
                        <Commission>
                            <Percent>10</Percent>
                        </Commission>
                    </RatePlan>
                </RatePlans>
                <RoomRates>
                    <RoomRate RoomTypeCode="KING" RatePlanCode="SPECIAL">
                        <Rates>
                            <Rate>
                                <Base AmountBeforeTax="1145.00" AmountAfterTax="1145.00" CurrencyCode="USD" />
                                <Total AmountBeforeTax="5725.00" AmountAfterTax="5725.00" CurrencyCode="USD" />
                                <Taxes>
                                    <Tax Amount="0.00" CurrencyCode="USD" />
                                </Taxes>
                                <Tpa_Extensions>
                                    <NightlyRate Date="12/28/2010" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                    <NightlyRate Date="12/29/2010" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                    <NightlyRate Date="12/30/2010" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                    <NightlyRate Date="12/31/2010" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                    <NightlyRate Date="1/1/2011" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                </Tpa_Extensions>
                            </Rate>
                        </Rates>
                    </RoomRate>
                </RoomRates>
                <BasicPropertyInfo HotelCode="1" HotelName="My Hotel!" />
            </RoomStay>
        </RoomStays>

So basically, in what way should I normalize this markup in order to combine all 3 requests so they can render the HTML markup specified?

+1  A: 

Try this:

 $children = array();
 foreach ($filelist as $file)
 {
   $dom = new DOMDocument();
   $dom->load($file);
   $children[] = $dom->firstChild;
 }
 $output = new DOMDocument();
 $output->appendChild($root = $output->createElement("rootelement"));
 foreach ($children as $child)
 {
   $imported = $output->importNode($child, true);
   $root->appendChild($imported);
 }
 // $output contains a DOMDocument with your aggregate document
 $newxml = $output->saveXML(); // if you want your XML as a string

Use $dom->loadXML instead of $dom->load if you want to load from a string that contains your XML instead of a disk file.

Once you have everything in one XML listing or DOM, you can either cut apart by iterating (worst), XPath in PHP (better) or XSLT (best).