php数组到xml,使用相同的数组键名

时间:2021-10-27 07:17:15

We are using pear's xml serializer to turn our request arrays into XML to submit to other servers for an XML response.

我们使用pear的xml序列化器将我们的请求数组转换为XML,以提交给其他服务器以获取XML响应。

The problem is, for one of the attributes we will need to submit an XML similar to this

问题是,对于其中一个属性,我们需要提交类似于此的XML

<totalRooms>
  <Room>
    ...
  </Room>
  <Room>
    ...
  </Room>
</totalRooms>

How do we compile this in PHP arrays so the Serializer produces the correct XML?

我们如何在PHP数组中编译它,以便Serializer生成正确的XML?

ie, we need:

即,我们需要:

Array("totalRooms" =>

Array("Room" => ...)

数组(“房间”=> ...)

Array("Room" => ...)

数组(“房间”=> ...)

)

Currently will not work because of the shared Key names "Room" end up overwriting each other... is there any other method?

目前无法正常工作,因为共享的密钥名称“房间”最终会相互覆盖......还有其他方法吗?

2 个解决方案

#1


Just making a guess, here, but from what I read from the doc, if you only have "room" unnamed and no further unnamed inner lists.

只是在这里猜测,但是从我从文档中读到的内容,如果你只有“空间”未命名而且没有其他未命名的内部列表。

Would work and be serialized okay as long as you set the defaultTagName option using $serializer->setOption("defaultTagName", 'Room');

只要使用$ serializer-> setOption(“defaultTagName”,'Room')设置defaultTagName选项,就可以正常工作和序列化;

That being done, the following would serialize

这样做,以下将序列化

    array("totalRooms" =>
      array(
        array("Room" => ...),
        array("Room" => ...),
        array("Room" => ...)
            )
         )

#2


We've taken this job from the server and given it to Flash (client-side platform), making the problem much easier to handle.

我们从服务器上接受了这项工作并将其交给Flash(客户端平台),使问题更容易处理。

Thank you Mr.Zombie for your response.

谢谢Mr.Zombie的回复。

#1


Just making a guess, here, but from what I read from the doc, if you only have "room" unnamed and no further unnamed inner lists.

只是在这里猜测,但是从我从文档中读到的内容,如果你只有“空间”未命名而且没有其他未命名的内部列表。

Would work and be serialized okay as long as you set the defaultTagName option using $serializer->setOption("defaultTagName", 'Room');

只要使用$ serializer-> setOption(“defaultTagName”,'Room')设置defaultTagName选项,就可以正常工作和序列化;

That being done, the following would serialize

这样做,以下将序列化

    array("totalRooms" =>
      array(
        array("Room" => ...),
        array("Room" => ...),
        array("Room" => ...)
            )
         )

#2


We've taken this job from the server and given it to Flash (client-side platform), making the problem much easier to handle.

我们从服务器上接受了这项工作并将其交给Flash(客户端平台),使问题更容易处理。

Thank you Mr.Zombie for your response.

谢谢Mr.Zombie的回复。