PHP | DOMDocument importNode() Function Last Updated : 27 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The DOMDocument::importNode() function is an inbuilt function in PHP which is used to return a copy of the node which need to import and associates it with the current document. Syntax: DOMNode DOMDocument::importNode( DOMNode $importedNode, bool $deep = FALSE ) Parameters: This function accepts two parameters as mentioned above and described below: $importedNode: This parameter holds the node which need to import. $deep: This parameter holds the Boolean value. If it set to TRUE then it will recursively import the subtree under the importedNode. Return Value: This function returns the copied node on success or FALSE, if it cannot be copied. Below program illustrates the DOMDocument::importNode() function in PHP: Program: php <?php // Create a new document $dom = new DOMDocument; // Load the XML document $dom->loadXML("<root><contact><email>[email protected]</email> <mobile>+91-987654321</mobile></contact></root>"); // Use getElementsByTagName() function to search // all elements with given local tag name $node = $dom->getElementsByTagName("contact")->item(0); // Create a new document $dom1 = new DOMDocument; $dom1->formatOutput = true; // Load the XML document $dom1->loadXML("<root><contactinfo><email>[email protected]</email> <mobile>+91-987654321</mobile></contactinfo></root>"); echo "Document before copying the nodes\n"; // Save the file in XML and display it echo $dom1->saveXML(); // Use importNode() function to import the node $node = $dom1->importNode($node, true); // Append child to the document $dom1->documentElement->appendChild($node); echo "\nDocument after copying the nodes\n"; // Save XML document and display it echo $dom1->saveXML(); ?> Output: Document before copying the nodes <?xml version="1.0"?> <root> <contactinfo><email>[email protected]</email> <mobile>+91-987654321</mobile></contactinfo> </root> Document after copying the nodes <?xml version="1.0"?> <root> <contactinfo><email>[email protected]</email> <mobile>+91-987654321</mobile></contactinfo> <contact><email>[email protected]</email> <mobile>+91-987654321</mobile></contact> </root> Reference: https://www.php.net/manual/en/domdocument.importnode.php Comment More infoAdvertise with us Next Article PHP | DOMDocument importNode() Function jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | DOMDocument load() Function The DOMDocument::load() function is an inbuilt function in PHP which is used to load an XML document from a file. Syntax: mixed DOMDocument::load( string $filename, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $filename: This parameter h 1 min read PHP | DOMDocument loadXML() Function The DOMDocument::loadXML() function is an inbuilt function in PHP which is used to load the XML file from a string. Syntax: mixed DOMDocument::loadXML( string $source, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $source: This parameter 2 min read PHP | DOMDocument loadHTML() Function The DOMDocument::loadHTML() function is an inbuilt function in PHP which is used to load HTML file from a string. Syntax: bool DOMDocument::loadHTML( string $source, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $source: This parameter ho 2 min read PHP | DOMDocument loadHTMLFile() Function The DOMDocument::loadHTMLFile() function is an inbuilt function in PHP which is used to load HTML from a file. Syntax: bool DOMDocument::loadHTMLFile( string $filename, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $filename: This paramet 2 min read PHP | DOMNode isSameNode() Function The DOMNode::isSameNode() function is an inbuilt function in PHP which indicates if two nodes are the same node or not. Syntax: bool DOMNode::isSameNode( DOMNode $node ) Parameters: This function accepts a single parameter $node which holds the node to be compared. Return Value: This function return 2 min read PHP | DOMDocument getElementById() Function The DOMDocument::getElementById() function is an inbuilt function in PHP which is used to search for an element with a certain id. Syntax: DOMElement DOMDocument::getElementById( string $elementId ) Parameters:This function accepts a single parameter $elementId which holds the id to search for. Retu 2 min read PHP | DOMDocument normalizeDocument() Function The DOMDocument::normalizeDocument() function is an inbuilt function in PHP which is used to normalize the document. This function is used to convert the document into the normal form if you saved and then loaded the document. Syntax: void DOMDocument::normalizeDocument( void ) Parameters: This func 1 min read PHP | DOMDocument save() Function The DOMDocument::save() function is an inbuilt function in PHP which is used to create an XML document from the DOM representation. This function is used after creating the new dom document from scratch. Syntax: int DOMDocument::save( string $filename, int $options = 0 ) Parameters: This function ac 2 min read PHP | DOMNode isSupported() Function The DOMNode::isSupported() function is an inbuilt function in PHP which is used to check if the asked feature is supported for the specified version. Syntax: bool DOMNode::isSupported( string $feature, string $version ) Parameters: This function accepts two parameters as mentioned above and describe 2 min read PHP | DOMDocument xinclude() Function The DOMDocument::xinclude() function is an inbuilt function in PHP which is used to substitute the XIncludes in a DOMDocument Object. Syntax: int DOMDocument::xinclude( int $options = 0 ) Parameters: This function accepts an optional single parameter $options which holds the libxml parameter. Return 2 min read Like