Share via


IXMLDOMNodeList Interface

The IXMLDOMNodeList interface supports iteration through the live collection, in addition to indexed access. For more information, see the Microsoft XML SDK 3.0 documentation available at the Microsoft Web site.

In addition to the methods inherited from the IDispatch interface, the IXMLDOMNodeList interface exposes the following methods.

Method

Description

get_item

Allows random access to individual nodes within the collection.

get_length

Retrieves the number of items in the collection.

nextNode*

Retrieves the next node in the collection.

reset*

Resets the iterator in the collection of nodes.

* Denotes an extension to the W3C DOM.

Remarks

A node list collection is live; that is, the addition and removal of nodes, and changes within nodes, are immediately reflected in the collection. This means that two successive requests for items using the same index can return two different items, depending on changes to the collection. This also means that changes to the node objects are immediately available in the nodes obtained from the list.

Example

The following example retrieves a pointer to an IXMLDOMNodeList interface and retrieves the number of nodes in the list.

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

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

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 all elements with node name "smil".
    bstrName = "smil";
    hr = pPlaylist->getElementsByTagName(bstrName, &pXMLNodeList);
    if (FAILED(hr)) goto EXIT;

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

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

See Also

Concepts

Programming Reference (C++)