代码之家  ›  专栏  ›  技术社区  ›  Eric

如何在PHP中在文档之间克隆节点[[副本]

  •  0
  • Eric  · 技术社区  · 15 年前


    DOMElement cloning and appending: ‘Wrong Document Error’

    我想复制元素的所有子节点 foo DOMDocument bar 在里面 DOMDocument公司 appendChild DOM_WRONG_DOCUMENT_ERR .

    有正确的方法吗?

    XML文档A

    <foo>
        <child />
        <child />
        <child />
    </foo>
    

    XML文档B

    <bar>
        <other-child />
        <other-child />
    </bar>
    

    :

    <bar>
        <other-child />
        <other-child />
        <child />
        <child />
        <child />
    </bar>
    

    这些元素不应假定为空,而是任意复杂的。

    1 回复  |  直到 8 年前
        1
  •  3
  •   Pekka    15 年前

    你可能想看看 DOMDocument::importNode .

    此函数返回要导入的节点的副本,并将其与当前文档相关联。

    推荐文章