DOMDocument::importNode
Import node into current document
&reftitle.description;
DOMNodeDOMDocument::importNode
DOMNodeimportedNode
booldeep
This function returns a copy of the node to import and associates it with
the current document.
&reftitle.parameters;
importedNode
The node to import.
deep
If set to &true;, this method will recursively import the subtree under
the importedNode.
To copy the nodes attributes deep needs to be set to &true;
&reftitle.returnvalues;
The copied node or &false;, if it cannot be copied.
&reftitle.errors;
DOMException is thrown if node cannot be imported.
&reftitle.examples;
DOMDocument::importNode example
Copying nodes between documents.
loadXML("text in child");
// 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("text in some element");
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 "" node
$newdoc->documentElement->appendChild($node);
echo "\nThe 'new document' after copying the nodes into it:\n";
echo $newdoc->saveXML();
?>
]]>
&example.outputs;
text in some element
The 'new document' after copying the nodes into it:
text in some element
text in child
]]>