removeChild Method

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

removeChild Method

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

[Script]

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]

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++]

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 childNode object is not removed.

C/C++ 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.

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter 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