XML DOM replaceChild () method
Definition and Usage
replaceChild () method to substitute another one of its child nodes.
If successful, the function is replaced node is returned, if it fails NULL.
grammar
elementNode.replaceChild(new_node,old_node)
参数 | 描述 |
---|---|
new_node | 必需。指定新的节点。 |
old_node | 必需。指定被替换的子节点。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and replace the first <book> node:
Examples
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.documentElement;
//create a book element
newNode=xmlDoc.createElement("book");
y=xmlDoc.getElementsByTagName("book")[0]
//replace the first book node with the new node
x.replaceChild(newNode,y);
x=xmlDoc.documentElement;
//create a book element
newNode=xmlDoc.createElement("book");
y=xmlDoc.getElementsByTagName("book")[0]
//replace the first book node with the new node
x.replaceChild(newNode,y);
try it"
Node objects