Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM cloneNode() Method

XML DOM cloneNode() Method


Element Object Reference Element Object


Definition and Usage

The cloneNode() method creates an exact copy of the specified node.

This method returns the cloned node.

Syntax

cloneNode(include_all)

Parameters Description
include_all Required. If the boolean parameter is set to true, the cloned node will clone all child nodes of the original node.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" Load into xmlDoc, copy the first node and add the copy to the end of the node list:

Example

xmlDoc

=

loadXMLDoc

(

"

books.xml

"

)

;

x

=

xmlDoc

.

getElementsByTagName

(

'

book

'

)

[

0

]

;

cloneNode

=

x

.

cloneNode

(

true

)

;

xmlDoc

.

documentElement

.

appendChild

(

cloneNode

)

;

//

Output the text values of all title nodes

y

=

xmlDoc

.

getElementsByTagName

(

"

title

"

)

;

for

(

i

=

0

;

i

<

y

.

length

;

i

++

)

{

document

.

write

(

y

[

i

]

.

childNodes

[

0

]

.

nodeValue

)

;

document

.

write

(

"


"

)

;

}

Output:

Everyday Italian

Harry Potter

XQuery Kick Start

Learning XML

Everyday Italian

Try it »


Element Object Reference Element Object