Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: DOMDocument::adoptNode - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: DOMDocument::adoptNode

2025-06-02

DOMDocument::adoptNode

(PHP >= 8.3)

DOMDocument::adoptNodeTransfer a node from another document

说明

public DOMDocument::adoptNode(DOMNode $node): DOMNode|false

Transfer a node from another document into the current document.

参数

node

The node to transfer.

返回值

The node that was transfered, or false on error.

错误/异常

DOM_NOT_SUPPORTED_ERR

Raised if the node type is not supported for document transfers.

示例

示例 #1 DOMDocument::adoptNode() example

Transfers the hello element from the first document to the second one.

<?php
$doc1
= new DOMDocument;
$doc1->loadXML("<container><hello><world/></hello></container>");
$hello = $doc1->documentElement->firstChild;

$doc2 = new DOMDocument;
$doc2->loadXML("<root/>");
$doc2->documentElement->appendChild($doc2->adoptNode($hello));

echo
$doc1->saveXML() . PHP_EOL;
echo
$doc2->saveXML();
?>

以上示例会输出:

<?xml version="1.0"?>
<container/>

<?xml version="1.0"?>
<root><hello><world/></hello></root>

参见

添加备注

用户贡献的备注 1 note

up
0
Anonymous
4 months ago
Note that this function will remove the node from the original XML document

官方地址:https://www.php.net/manual/en/domdocument.adoptnode.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3