IXMLDOMNodeList::nextNode

banner art

Previous Next

IXMLDOMNodeList::nextNode

The nextNode method retrieves the next node in the IXMLDOMNodeList collection.

Syntax

  HRESULT nextNode(
 IXMLDOMNode** ppNextItem
);

Parameters

ppNextItem

[out] Pointer to a pointer to an IXMLDOMNode interface containing the next node in the collection, or NULL if there is no next node. 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.

Remarks

The iterator initially points before the first node in the list so that the first call to nextNode retrieves the first node in the list.

This method returns NULL when the current node is the last node or there are no items in the list. When the current node is removed from the list, subsequent calls to nextNode return NULL. The iterator must be reset by calling the reset method.

This method is an extension of the World Wide Web Consortium (W3C) Document Object Model (DOM).

Example Code

The following example retrieves a pointer to an IXMLDOMNodeList interface and uses its nextNode method to iterate through the collection.

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

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

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

// 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;

// Retrieve a list of media elements.
bstrName = "media";
hr = pPlaylist->getElementsByTagName(bstrName, &pXMLNodeList);
if (FAILED(hr)) goto EXIT;

// Retrieve the number of elements in the list.
hr = pXMLNodeList->get_length(&lCount);
if (FAILED(hr)) goto EXIT;

// Retrieve each element in the list.
for (int i = 0; i < lCount; i++)
{
    hr = pXMLNodeList->nextNode(&pXMLNode);
    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

Previous Next