removeChild Method

 

Removes the specified child node from the list of children and returns it.

var objXMLDOMNode = oXMLDOMNode.removeChild(childNode);  

Parameters

childNode
An object. Child node to be removed from the list of children of this node.

Return Value

An object. Returns the removed child node.

Example

The following script example creates an IXMLDOMNode object (currNode), removes a child node from it, and displays the text of the removed node.

System_CAPS_ICON_note.jpg Note

You can use books.xml to run this sample code.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
var root;
var currNode;
var oldChild;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   WScript.Echo("You have error " + myErr.reason);
} else {
   root = xmlDoc.documentElement;
   currNode = root.childNodes.item(1);
   oldChild = currNode.removeChild(currNode.childNodes.item(1));
   WScript.Echo(oldChild.text);
}

Output

Midnight Rain

HRESULT removeChild(  
    IXMLDOMNode *childNode,  
    IXMLDOMNode **outOldChild);  

Parameters

childNode[in]
The child node to be removed from the list of children of this node.

outOldChild[out, retval]
The removed child node. If Null, the childNode object is not removed.

Return Values

S_OK
The value returned if successful.

E_INVALIDARG
The value returned if the oldChild parameter is not a child of this node, when the specified oldChild is read-only and cannot be removed, or when oldChild is Null.

E_FAIL
The value returned if an error occurs.

Implemented in: MSXML 3.0 and MSXML 6.0

IXMLDOMAttribute
IXMLDOMCDATASection
IXMLDOMCharacterData
IXMLDOMComment
IXMLDOMDocument-DOMDocument
IXMLDOMDocumentFragment
IXMLDOMDocumentType
IXMLDOMElement
IXMLDOMEntity
IXMLDOMEntityReference
IXMLDOMNode
IXMLDOMNotation
IXMLDOMProcessingInstruction
IXMLDOMText

Show: