XML DOM cloneNode() Method
Complete Element Object Reference
Definition and Usage
The cloneNode() method creates an exact copy of a specified node.
This method returns the cloned node.
Syntax
Parameter |
Description |
include_all |
Required. If the
Boolean
parameter is set to true, the cloned node clones all the child nodes of the
original node as well |
Example
The following code fragment loads "books.xml"
into xmlDoc using
loadXMLDoc() and copies the first <book> node, then adds the
copy to the end of the node list:
xmlDoc=loadXMLDoc("books.xml");
oldNode=xmlDoc.getElementsByTagName('book')[0];
newNode=oldNode.cloneNode(true);
xmlDoc.documentElement.appendChild(newNode);
//Output all titles
y=xmlDoc.getElementsByTagName("title");
for (i=0;i<y.length;i++)
{
document.write(y[i].childNodes[0].nodeValue);
document.write("<br />");
}
|
Output:
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
Everyday Italian
|
Try-It-Yourself Demos
cloneNode() -
Copy a node and append it
Complete Element Object Reference
Whether you're new to XML or already an advanced user, the user-friendly views
and powerful entry helpers, wizards, and debuggers in XMLSpy are designed to
meet your XML and Web services development needs from start to finish.
- XML editor
- Graphical XML Schema / DTD editors
- XSLT 1.0/2.0 editor, debugger, profiler
- XQuery editor, debugger, profiler
- Support for Office Open XML (OOXML)
- Graphical WSDL editor & SOAP debugger
- Java, C#, C++ code generation
- And much more!
Download a fully functional free 30-day trial today!
|