IXMLDOMNode::get_childNodes

The get_childNodes method retrieves a list of the child nodes.

HRESULT get_childNodes(
IXMLDOMNodeList** ppChildList
);

Arguments

ppChildList

[out] Pointer to a pointer to an IXMLDOMNodeListIXMLDOMNodeList Interface that represents a list of children in the current node. This method calls AddRef internally. To avoid memory leaks, you must call Release when you are finished using the interface.

Return Value

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

Remarks

A pointer to an IXMLDOMNodeList interface is returned even if there are no children of the node. In such a case, the length of the list will be set to zero. For information about valid child node types for each node, see XML DOM Enumerated Constants.

The value of the IXMLDOMNodeList interface retrieved depends on the type of node on which the get_childNodes method is called, as shown in the following table. For example, if the node type is NODE_ELEMENT, a list of child nodes for that element node is retrieved.

Node type

Value retrieved

NODE_ATTRIBUTE NODE_DOCUMENT NODE_ELEMENT

Retrieves a pointer to an IXMLDOMNodeList interface that contains a list of all child nodes for the specified node.

NODE_COMMENT NODE_PROCESSING_INSTRUCTION NODE_TEXT

Retrieves a pointer to an IXMLDOMNodeList interface with a length of zero. This node type cannot have children.

Example

The following example uses the get_childNodes method (collection) to return a pointer to an IXMLDOMNodeList interface, and then iterates through the collection, retrieving the name of each item.

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

// Declare variables.
IWMSServer*           pServer;
IXMLDOMDocument*      pPlaylist;
IXMLDOMElement*       pXMLElement;
IXMLDOMNodeList*      pXMLNodeList;
IXMLDOMNode*          pXMLNode;

HRESULT               hr;
CComVariant           varValue;
CComBSTR              bstrName;
long                  lCount;
VARIANT_BOOL          bIsSuccessful;

// 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.
varValue = "c:\\wmpub\\wmroot\\simple.wsx";
hr = pPlaylist->load(varValue, &bIsSuccessful);
if (FAILED(hr)) goto EXIT;

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

    // Retrieve a pointer to the IXMLNodeList interface.
    hr = pXMLElement->get_childNodes(&pXMLNodeList);
    if (FAILED(hr)) goto EXIT;

    // Retrive the total count of nodes and display the
    // name of each node.
    hr = pXMLNodeList->get_length(&lCount);
    if (FAILED(hr)) goto EXIT;
    for (int i = 0; i < lCount; i++)
    {
        hr = pXMLNodeList->get_item(i, &pXMLNode);
        if (FAILED(hr)) goto EXIT;
        hr = pXMLNode->get_nodeName(&bstrName);
        if (FAILED(hr)) goto EXIT;

        // Release temporary COM objects.
        pXMLNode->Release();
    }
}

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

Requirements

Header: wmsserver.h.

Library: WMSServerTypeLib.dll.

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

See Also

Reference

IXMLDOMNode Interface

IXMLDOMNodeList Interface

Concepts

XML DOM Methods (C++)