XML DOM cloneNode () method
Definition and Usage
cloneNode () method creates an exact copy of the specified node.
This method returns a clone of the node.
grammar
cloneNode(include_all)
参数 | 描述 |
---|---|
include_all | 必需。假如布尔参数被设置为 true,那么被克隆的节点会克隆原节点的所有子节点。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc copies the first <book> node and to add a replica to the end node of the list:
Examples
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("
");
}
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("
");
}
Output:
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
Everyday Italian
try it"
Element object