XML DOM replaceChild () method
Definition and Usage
replaceChild () method replaces the child nodes to other nodes.
If successful, the function is replaced node is returned, if it fails to return 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> element:
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"
Element object