2

I'm dealing with a SOAP client response for a flight booking application, I successfully got the response, See the response below:

<arzoo__response> <Response__Depart> <OriginDestinationOptions> <OriginDestinationOption> <FareDetails> <ChargeableFares> <ActualBaseFare>4850</ActualBaseFare> <Tax>4267</Tax> <STax>31</STax> <SCharge>0</SCharge> <TDiscount>0</TDiscount> <TPartnerCommission>0</TPartnerCommission> </ChargeableFares> <NonchargeableFares> <TCharge>0</TCharge> <TMarkup>0</TMarkup> <TSdiscount>0</TSdiscount> </NonchargeableFares> </FareDetails> <FlightSegments> <FlightSegment> <AirEquipType>321</AirEquipType> <ArrivalAirportCode>DEL</ArrivalAirportCode> <ArrivalDateTime>2013-05-20T08:00:00</ArrivalDateTime> <DepartureAirportCode>BOM</DepartureAirportCode> <DepartureDateTime>2013-05-20T06:00:00</DepartureDateTime> <FlightNumber>601</FlightNumber> <OperatingAirlineCode>AI</OperatingAirlineCode> <OperatingAirlineFlightNumber>601</OperatingAirlineFlightNumber> <RPH></RPH> <StopQuantity>0</StopQuantity> <airLineName>Air India</airLineName> <airportTax>4267</airportTax> <imageFileName>http://live.arzoo.com/FlightWS/image/AirIndia.gif</imageFileName> <viaFlight></viaFlight> <BookingClass> <Availability>4</Availability> <ResBookDesigCode>U</ResBookDesigCode> </BookingClass> <BookingClassFare> <adultFare>4850</adultFare> <bookingclass>U</bookingclass> <classType>Economy</classType> <farebasiscode>fjyS3YyUlEusLfJ4bwgPvQ==</farebasiscode> <Rule>This fare is Refundable &lt;br&gt; Baggage : 25K&lt;br&gt;Booking Class : U|Re-Schedule Charges: Rs. 750 per sector + Fare difference (If any) +admin fee 500 + Service Fee of Rs. 250 Sector .|Cancellation Charges : Basic fare +Airline administration fee 500 + Service Charges 250 Per Passenger Per Sector . |</Rule> <adultCommission>0</adultCommission> <childCommission>0</childCommission> <commissionOnTCharge>0</commissionOnTCharge> </BookingClassFare> <Discount>0</Discount> <airportTaxChild>0</airportTaxChild> <airportTaxInfant>0</airportTaxInfant> <adultTaxBreakup>2800,147,1320</adultTaxBreakup> <childTaxBreakup>0,0,0</childTaxBreakup> <infantTaxBreakup>0,0,0</infantTaxBreakup> <octax>0</octax> </FlightSegment> </FlightSegments> <id>arzoo11</id> <key>wtZcSVMY/gphWFSOTFWg8oKRnosq3p9wt7R4SjMB0EUK8sDjVS91GicTJzH+TWN+pNURIyTJYKOW O8yH8+0tzpA4t8aEEvzaOE6ZnTtBotFDwLtSiN0xXqMsaDl8diV51l7d9ata/3rxTgfh9d8ZSmFY VI5MVaDywdHNcjAR1vwnEycx/k1jftlsnmWWqYGnJxMnMf5NY36YIq2FtLkfcHtsd+IDEhxpxJuT v4YyS+QnEycx/k1jftlsnmWWqYGnJxMnMf5NY37ZbJ5llqmBpycTJzH+TWN+GlZsae+KA6L3dlms eLkXZFKXPvd5FAnBXnTfRGc5sz+UC8CsZNzDV2FYVI5MVaDyFiThuG7WKPhzqWDbQb1E1IqUKT5I FtF6OaCYjb6EFGhDwLtSiN0xXt7N3OmPGVH2v18OFlhFoI+A/uAfnTovYr9fDhZYRaCPgP7gH506 L2K/Xw4WWEWgj4D+4B+dOi9iv18OFlhFoI+A/uAfnTovYr9fDhZYRaCPgP7gH506L2K/Xw4WWEWg j4D+4B+dOi9iv18OFlhFoI/87KPqwdBsCm4nF4DlZwRNQ/zni8QE42g8S0GV1z3SJXaOdoTFisn9 v18OFlhFoI+ThOYsjNAbXEP854vEBONoPEtBldc90iVD/OeLxATjaAwTg0ygCEBmEgnKEhG4Md1D /OeLxATjaDxLQZXXPdIlQ/zni8QE42jXGTnbB/ydvR4daAuN34kWYVhUjkxVoPJtRWbi6bZrXL9f DhZYRaCPgP7gH506L2K/Xw4WWEWgj4D+4B+dOi9iv18OFlhFoI8KriAmVoEyR3OpYNtBvUTUp1Mf I240+obPusGaAOeuxg==</key> </OriginDestinationOption> </OriginDestinationOptions> </Response__Depart> </arzoo__response> 

Now i have to display them as :

Base Price: 4850 Tax: 31 STax: 31 SCharge: 0 TDiscount: 0 TPartnerCommission: 0 ..................... Arrival Airport Code: DEL .....................

I tried several methods using foreach():

 $result = $client->__call('getAvailability',array($test)); $xml = simplexml_load_string($result); foreach($xml->OriginDestinationOption as $od){ foreach($od->FareDetails as $fd){ foreach($fd->ChargeableFares as $cf){ echo $cf->ActualBaseFare; } } } 

but never sot it out. Can any one please help me out on this ? Your help must appreciated. Thanks in advance

1 Answer 1

3

You are trying to access OriginDestinationOption as though it is a direct child of the XML response, but the structure is actually like this:

<arzoo__response> <Response__Depart> <OriginDestinationOptions> <OriginDestinationOption> 

So, since your $xml will represent the arzoo__response element, you need to traverse the other elements in between:

foreach($xml->Response__Depart->OriginDestinationOptions->OriginDestinationOption as $od) 
Sign up to request clarification or add additional context in comments.

1 Comment

This answer solved my problem: I hadn't noticed because of poor identing in the Soap XML example provided to me that I needed an extra level ->PayerWithAnswers. So draw a structure as recommended by @IMSoP . I must remember not to panic with Soap/XML

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.