removeChild Method
Removes the specified child node from the list of children and returns it.
Script Syntax
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.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var root;
var currNode;
var oldChild;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
var myErr = xmlDoc.parseError;
alert("You have error " + myErr.reason);
} else {
root = xmlDoc.documentElement;
currNode = root.childNodes.item(1);
oldChild = currNode.removeChild(currNode.childNodes.item(1));
alert(oldChild.text);
}
Visual Basic Syntax
Set objXMLDOMNode = oXMLDOMNode.removeChild(childNode)
Parameters
- childNode
- An object. The 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 Microsoft® Visual Basic® example creates an IXMLDOMNode object (currNode), removes a child node from it, and displays the text of the removed node.
Dim xmlDoc As New Msxml2.DOMDocument50
Dim root As IXMLDOMElement
Dim currNode As IXMLDOMNode
Dim oldChild As IXMLDOMNode
xmlDoc.async = False
xmlDoc.Load ("books.xml")
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
MsgBox("You have error " & myErr.reason)
Else
Set root = xmlDoc.documentElement
Set currNode = root.childNodes.Item(1)
Set oldChild = currNode.removeChild(currNode.childNodes.Item(1))
MsgBox oldChild.Text
End If
C/C++ Syntax
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
childNodeobject is not removed.
C/C++ Return Values
- S_OK
- The value returned if successful.
- E_INVALIDARG
- The value returned if the
oldChildparameter is not a child of this node, when the specifiedoldChildis read-only and cannot be removed, or whenoldChildis Null. - E_FAIL
- The value returned if an error occurs.
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button
in the upper-left corner of the page.
See Also
Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText
