banner art

Previous Next


The removeChild method removes the specified child node from the list of children and returns it.


  HRESULT removeChild(
 IXMLDOMNode* pChildNode, 
 IXMLDOMNode** ppOutOldChild



[in] Pointer to an IXMLDOMNode interface containing the child node to be removed from the list of children of this node.


[out] Pointer to a pointer to an IXMLDOMNode interface that represents the removed child node. If NULL, no object is created. This method calls AddRef internally. To avoid memory leaks, you must call Release when you are finished using the interface.

Return Values

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Example Code

The following example retrieves a pointer an IXMLDOMNode interface and removes a child node from its list of children.

#include "wmsserver.h"
#include <atlbase.h> // Includes CComVariant and CComBSTR.

// Declare variables.
IWMSServer*         pServer;
IXMLDOMDocument*    pPlaylist;
IXMLDOMElement*     pXMLElement;
IXMLDOMNodeList*    pXMLNodeList;
IXMLDOMNode*        pXMLNodeCur;
IXMLDOMNode*        pXMLNodeRmv;
IXMLDOMNode*        pXMLNodeOld;

HRESULT             hr;
VARIANT_BOOL        bIsSuccessful;
CComVariant         varFile;

// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer, NULL, CLSCTX_ALL, 
       IID_IWMSServer, (void**)&pServer);
if (FAILED(hr)) goto EXIT;

// Create the playlist object.
hr = pServer->CreatePlaylist(&pPlaylist);

// Load a sample playlist file.
varFile = "c:\\wmpub\\wmroot\\simple.wsx";
hr = pPlaylist->load(varFile, &bIsSuccessful);
if (FAILED(hr)) goto EXIT;

if (bIsSuccessful)
    // Retrieve a pointer to an IXMLDOMElement interface.
    hr = pPlaylist->get_documentElement(&pXMLElement);
    if (FAILED(hr)) goto EXIT;

    // Retrieve a list of child nodes.
    hr = pXMLElement->get_childNodes(&pXMLNodeList);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the second child node.
    hr = pXMLNodeList->get_item(1, &pXMLNodeCur);
    if (FAILED(hr)) goto EXIT;

    // Retrieve a list of child nodes from the current node.
    hr = pXMLNodeCur->get_childNodes(&pXMLNodeList);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the first child of the current node.
    hr = pXMLNodeList->get_item(0, &pXMLNodeRmv);
    if (FAILED(hr)) goto EXIT;

    // Remove the child of the current node.
    hr = pXMLNodeCur->removeChild(pXMLNodeRmv, &pXMLNodeOld);
    if (FAILED(hr)) goto EXIT;

    // TODO: Release temporary COM objects and uninitialize COM.


Header: wmsserver.h.

Library: WMSServerTypeLib.dll.

Platform: Windows ServerĀ 2003 family, Windows ServerĀ 2008 family.

See Also

Previous Next