Change language

PHP DOMDocument importNode () function

Syntax:
DOMNode DOMDocument::importNode (DOMNode $importedNode, bool  $deep = FALSE)
Parameters:This function takes two parameters as above and described below:
  • $importNode :this parameter contains the node to be imported.
  • $deep:this parameter contains a boolean value. If set to TRUE, it will recursively import the subtree in the imported node.
Return Value:This function returns the copied node on success or FALSE if it is not possible copy.The following program illustrates the DOMDocument::importNode() function in PHP:Program :  
// Create a new one document $dom = new DOMDocument;  
// Load XML document $dom -> loadXML ("< root > < contact > < email > [email protected]< / email > < mobile > + 91-987654321 < / mobile > < / contact > < / root > ");  
// Use the getElementsByTagName() function to search
// all elements with the given local tag name $node = $dom -> getElementsByTagName ( " contact " ) -> item (0);  
// Create a new document $dom1 = new DOMDocument; $dom1 -> formatOutput = true;  
// Load XML document $dom1 -> loadXML ("< root > < contactinfo > < email > [email protected]< / email > < mobile > + 91-987654321 < / mobile > < / contactinfo > < / root > "); echo " Document before copying the nodes " ;  
// Save the file as XML and display it echo $dom1 -> saveXML();  
// Use the importNode() function to import the node $node = $dom1 -> importNode ( $node , true);  
// Add a child element to the document $dom1 -> documentElement-> appendChild ( $node ); echo " Document after copying the nodes " ;  
// Save the XML document and display it echo $dom1 -> saveXML();  
?>
Exit:
Document before copying the nodes  < root > < contactinfo > < email > [email protected]< / email > < mobile > + 91-987654321 < / mobile > < / contactinfo > < / root > Document after copying the nodes  < contactinfo > < email > [email protected]< / email > < mobile > + 91-987654321 < / mobile > < / contactinfo > < contact > < email > [email protected]< / email > < mobile > + 91-987654321 < / mobile > < / contact > < / root >
Link: https://www.php.net/ manual / en / domdocument.importnode.php

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically