I send xml data to a remote server(website). Getting response of it. Now I want to save that received values in variables for further use. But I am not able to do so.
Here is the complete code:
<?php $xml = '<?xml version="1.0" encoding="UTF-8" ?> <Request> <Source> <RequestorID Client="1921" EMailAddress="XML.ALTECH@TRAVELDEN.COM" Password="PASS" /> <RequestorPreferences Language="en" Currency="GBP" Country="GB"> <RequestMode>SYNCHRONOUS</RequestMode> </RequestorPreferences> </Source> <RequestDetails> <SearchHotelPriceRequest> <ItemDestination DestinationType="city" DestinationCode="LON" /> <ImmediateConfirmationOnly /> <PeriodOfStay> <CheckInDate>2015-12-08</CheckInDate> <Duration>2</Duration> </PeriodOfStay> <IncludeRecommended/> <Rooms> <Room Code="DB" NumberOfRooms="1"> <ExtraBeds> <Age>5</Age> </ExtraBeds> </Room> <Room Code="TB" NumberOfCots="2"> <ExtraBeds> <Age>10</Age> </ExtraBeds> </Room> <Room Code="SB" /> </Rooms> <StarRating MinimumRating="true">3</StarRating> <OrderBy>pricelowtohigh</OrderBy> <NumberOfReturnedItems>10</NumberOfReturnedItems> </SearchHotelPriceRequest> </RequestDetails> </Request> ' ; $url = 'https://interface.demo.gta-travel.com/wbsapi/RequestListenerServlet'; //setting the curl parameters. $headers = array( "Content-type: text/xml;charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "SOAPAction: \"run\"" ); try{ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); // send xml request to a server curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); echo $ch; $data = curl_exec($ch); echo $data; if($data === false){ $error = curl_error($ch); echo $error; die('error occured'); }else{ $newxml=$data; echo $data; echo '<pre>'; echo htmlspecialchars(print_r($newxml, true)); echo '<pre>'; $dataPOST = trim(file_get_contents($data)); $xmlData = simplexml_load_string($dataPOST); echo $xmlData->Response->ResponseDetails->SearchHotelPriceResponse->HotelDetails->Hotel['HasMap']; } curl_close($ch); }catch(Exception $e){ echo 'Message: ' .$e->getMessage();die("Error"); } ?>
Error I am recieveing is "Trying to get property of non-object" at line
$dataPOST = trim(file_get_contents($data)); $xmlData = simplexml_load_string($dataPOST); echo $xmlData->Response->ResponseDetails->SearchHotelPriceResponse->HotelDetails->Hotel['HasMap'];
Here is output code that i am reciveing from server in xml
<?xml version="1.0" encoding="UTF-8"?> <Response ResponseReference="REF_D_010_1921-1001448826920884"> <ResponseDetails Language="en"> <SearchHotelPriceResponse> <HotelDetails> <Hotel HasExtraInfo="true" HasMap="true" HasPictures="true"> <City Code="LON"><![CDATA[London]]></City> <Item Code="KEN8"><![CDATA[Grosvenor Kensington]]></Item> <LocationDetails><Location Code="G1"><![CDATA[Central]]></Location> <Location Code="10"><![CDATA[Kensington]]></Location></LocationDetails> <StarRating>4</StarRating> <HotelRooms> <HotelRoom Code="DB" ExtraBed="true" NumberOfExtraBeds="1" NumberOfRooms="1"/> <HotelRoom Code="TB" ExtraBed="true" NumberOfCots="2" NumberOfExtraBeds="1" NumberOfRooms="1"/> <HotelRoom Code="SB" NumberOfRooms="1"/> </HotelRooms> <RoomCategories> <RoomCategory Id="001:GRO9:5144:S5063:5758:22498"> <Description><![CDATA[Standard Triple]]></Description> <ItemPrice CommissionPercentage="0.00" Currency="GBP">1272.00</ItemPrice> <Confirmation Code="IM"> <![CDATA[AVAILABLE]]> </Confirmation> <SharingBedding>false</SharingBedding> <Meals> <Basis Code="N"><![CDATA[None]]></Basis></Meals> </RoomCategory> <RoomCategory Id="001:KEN8:5144:S5063:5705:22498"> <Description><![CDATA[Standard Triple]]></Description> <ItemPrice CommissionPercentage="0.00" Currency="GBP">1413.00</ItemPrice> <Confirmation Code="IM"><![CDATA[AVAILABLE]]></Confirmation> <SharingBedding>false</SharingBedding> <Meals><Basis Code="B"><![CDATA[Breakfast]]></Basis> <Breakfast Code="F"><![CDATA[Full]]> </Breakfast></Meals> </RoomCategory> </RoomCategories></Hotel> </HotelDetails> </SearchHotelPriceResponse> </ResponseDetails> </Response>
No comments:
Post a Comment