小编Kyr*_*yus的帖子

以递归方式合并两个XML文件

我想以递归方式将2个XML文件合并为一个.例如 :

第一档:

<root>
    <branch1>
        <node1>Test</node1>
    </branch1>
    <branch2>
        <node>Node from 1st file</node>
    </branch2>
</root>
Run Code Online (Sandbox Code Playgroud)

第二档:

<root>
    <branch1>
        <node2>Test2</node2>
    </branch1>
    <branch2>
        <node>This node should overwrite the 1st file branch</node>
    </branch2>
    <branch3>
        <node>
            <subnode>Yeah</subnode>
        </node>
    </branch3>
</root>
Run Code Online (Sandbox Code Playgroud)

合并文件:

<root>
    <branch1>
        <node1>Test</node1>
        <node2>Test2</node2>
    </branch1>
    <branch2>
        <node>This node should overwrite the 1st file branch</node>
    </branch2>
    <branch3>
        <node>
            <subnode>Yeah</subnode>
        </node>
    </branch3>
</root>
Run Code Online (Sandbox Code Playgroud)

我想将第二个文件添加到第一个文件中.当然,可以使用任何深度的XML来完成合并.

我在Google上搜索过,但没有找到一个正常运行的脚本.

你能帮我吗 ?

php xml merge simplexml

8
推荐指数
1
解决办法
2909
查看次数

标签 统计

merge ×1

php ×1

simplexml ×1

xml ×1