Assume that $source and $dest are instances of DOMDocument. Assume that $sourcedoc contains an element with ID 'sourceID' and that $destdoc contains an element with ID 'destID'. Assume that we have already set up source and destination element variables thus:
<?php
$src = $sourcedoc->getElementById('sourceID');
$dst = $destdoc->getElementById('destID');
?>
Finally, assume that $sel has more than one child node.
In order to import the child elements of $src as children of $dst, you might do something like this:
<?php
$src = $dest->importNode($src, TRUE);
foreach ($src->childNodes as $el) $dst->appendChild($el);
?>
But this does not work. foreach gets confused, because (as noted below) appending an imported element to another existing element in the same document causes it to be removed from its current parent element.
Therefore, the following technique should be used:
<?php
foreach ($src->childNodes as $el) $dst->appendChild($destdoc->importNode($el, TRUE));
?>
PHP.mk документација
DOMDocument::importNode
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
domdocument.importnode.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
domdocument.importnode.php
DOMDocument::importNode
Референца за `domdocument.importnode.php` со подобрена типографија и навигација.
DOMDocument::importNode
класата mysqli_driver
DOMDocument::importNode — Увоз на јазол во тековниот документ
= NULL
Оваа функција враќа копија на јазолот за увоз и го поврзува со тековниот документ.
Параметри
Вратени вредности
Копираниот јазол или false, ако не може да се копира.
Errors/Exceptions
DOMException се фрла ако јазолот не може да се увезе.
Примери
Пример #1 Го префрла елементот hello од првиот документ во вториот. example
Копирање јазли помеѓу документи.
<?php
$orgdoc = new DOMDocument;
$orgdoc->loadXML("<root><element><child>text in child</child></element></root>");
// The node we want to import to a new document
$node = $orgdoc->getElementsByTagName("element")->item(0);
// Create a new document
$newdoc = new DOMDocument;
$newdoc->formatOutput = true;
// Add some markup
$newdoc->loadXML("<root><someelement>text in some element</someelement></root>");
echo "The 'new document' before copying nodes into it:\n";
echo $newdoc->saveXML();
// Import the node, and all its children, to the document
$node = $newdoc->importNode($node, true);
// And then append it to the "<root>" node
$newdoc->documentElement->appendChild($node);
echo "\nThe 'new document' after copying the nodes into it:\n";
echo $newdoc->saveXML();
?>Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред
The 'new document' before copying nodes into it:
<?xml version="1.0"?>
<root>
<someelement>text in some element</someelement>
</root>
The 'new document' after copying the nodes into it:
<?xml version="1.0"?>
<root>
<someelement>text in some element</someelement>
<element>
<child>text in child</child>
</element>
</root>
Белешки од корисници 2 забелешки
c точка 1 на smithies точка org ¶
пред 16 години
Fitopaldi ¶
20 години пред
importNode returns a copy of the node to import and associates it with the current document, but not import the node to the current DOMDocument. Use appendChild for import the copy of the node to current DOMDocument.
<?
$domNode = $dom->importNode($aDomNode, true);
$currentDomDocument->appendChild($domNode);
?>