相关疑难解决方法(0)

如何将数组转换为SimpleXML

如何在PHP中将数组转换为SimpleXML对象?

php xml arrays simplexml

277
推荐指数
10
解决办法
39万
查看次数

将多维数组转换为XML

在您评论这可能是重复之前,请阅读下面的粗体线.这与SimpleXML无关.

让我首先展示如何布局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>
Run Code Online (Sandbox Code Playgroud)

在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" => …
Run Code Online (Sandbox Code Playgroud)

php xml object

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

php ×2

xml ×2

arrays ×1

object ×1

simplexml ×1