Please read the highlighted line below before commenting that this might be a duplicate. This has nothing to do with SimpleXML.
Let me begin by showing you how XML should be laid out. Please ignore namespaces:
<hot:SearchHotels> <hot:request> <hot1:Destination>?</hot1:Destination> <hot1:HotelCityName>?</hot1:HotelCityName> <hot1:HotelLocationName>?</hot1:HotelLocationName> <hot1:HotelName>?</hot1:HotelName> <hot1:CheckIn>?</hot1:CheckIn> <hot1:CheckOut>?</hot1:CheckOut> <hot1:RoomsInformation> <hot1:RoomInfo> <hot1:AdultNum>?</hot1:AdultNum> <hot1:ChildNum>?</hot1:ChildNum> <hot1:ChildAges> <hot1:ChildAge age="?"/> </hot1:ChildAges> </hot1:RoomInfo> </hot1:RoomsInformation> <hot1:MaxPrice>?</hot1:MaxPrice> <hot1:StarLevel>?</hot1:StarLevel> <hot1:AvailableOnly>?</hot1:AvailableOnly> <hot1:PropertyType>?</hot1:PropertyType> <hot1:ExactDestination>?</hot1:ExactDestination> </hot:request> </hot:SearchHotels>
The notice under hot1: RoomsInformation is RoomInfo. I should be able to send multiple RoomInfo nodes. But I am using a PHP class to convert an array to this object to send via SOAP.
Here my array is converted to an object before it:
$param = array( "Destination" => $destcode, "HotelCityName" => $city, "HotelLocationName" => "", "HotelName" => "", "CheckIn" => date("Ymd", strtotime($checkin)), "CheckOut" => date("Ymd", strtotime($checkout)), "RoomsInformation" => array ( "RoomInfo" => array( "AdultNum" => 2, "ChildNum" => 1, "ChildAges" => array( "ChildAge" => array( "age"=>11 ) ) ), "RoomInfo" => array( "AdultNum" => 1, "ChildNum" => 0, "ChildAges" => array( "ChildAge" => array( "age"=>0 ) ) ) ), "MaxPrice" => 0, "StarLevel" => 0, "AvailableOnly" => "false", "PropertyType" => "NotSet", "ExactDestination" => "false" ); $param = arrayToObject($param) ; $obj = new stdClass(); $obj->request=$param; $result = $test->SearchHotels($obj) ;
The problem is that after converting to an object, there is only 1 RoomInfo and the last one. My thought is that the RoomsInformation array has 2 identical KEY names. So how can I do this job?
For your information, the SOAP class and the arrayToObject function are used here:
http://pastebin.com/SBUN0FAF