XML DOM Clone Node - XML DOM

What is Clone Node operation in XML DOM?

The duplicate copy of a specified node is created by a Clone node operation and for this operation cloneNode() is used.

cloneNode()

The duplicate copy of the node is returned by this node which represents as a generic copy constructor for the nodes. There is no parent node and no user data for the duplicate node.

Syntax

The syntax for cloneNode() method is −

  • deep − If true, recursively clones the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
  • This method returns the duplicate node.

Example

An XML document node.xml is parsed into an XML DOM object and a duplicate copy of the first Employee element is created.

It is observed that the cloneNode() param is set to true. So each of the child element of the Employee element is copied.

Execution

The file is saved as clonenode_example.htm on the server path and this file should be on the same path as that of node.xml in the server. The output appears as follows:

It is observed that the first Employee element is completely cloned.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XML DOM Topics