请在您评论这可能是重复的内容之前,先阅读下面加粗的行。这与SimpleXML无关。
我先展示一下XML应该如何布局,请忽略命名空间:
问题在于转换为对象后,只有一个RoomInfo,而且是最后一个。我的想法是因为RoomsInformation数组有2个相同的KEY名称。那么我该如何解决这个问题呢?
供您参考,这是我使用的SOAP类和arrayToObject函数: http://pastebin.com/SBUN0FAF
我先展示一下XML应该如何布局,请忽略命名空间:
<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>
<!--Zero or more repetitions:-->
<hot1:RoomInfo>
<hot1:AdultNum>?</hot1:AdultNum>
<hot1:ChildNum>?</hot1:ChildNum>
<!--Optional:-->
<hot1:ChildAges>
<!--Zero or more repetitions:-->
<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>
请注意在hot1:RoomsInformation下有RoomInfo。我应该能够发送多个RoomInfo节点。但我正在使用PHP类将数组转换为此对象以通过SOAP提交。
在它被转换为对象之前,这是我的数组:
$param = array(
"Destination" => $destcode,
"HotelCityName" => $city,
"HotelLocationName" => "",
"HotelName" => "",
"CheckIn" => date("Y-m-d", strtotime($checkin)),
"CheckOut" => date("Y-m-d", 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) ;
问题在于转换为对象后,只有一个RoomInfo,而且是最后一个。我的想法是因为RoomsInformation数组有2个相同的KEY名称。那么我该如何解决这个问题呢?
供您参考,这是我使用的SOAP类和arrayToObject函数: http://pastebin.com/SBUN0FAF