IXMLDOMNodeList::get_item

banner art

Previous Next

IXMLDOMNodeList::get_item

The get_item method allows random access to individual nodes within the IXMLDOMNodeList collection.

Syntax

  HRESULT item(
 long lIndex,
 IXMLDOMNode** ppListItem
);

Parameters

lIndex

[in] long containing the index of the item within the collection. The first item is zero.

ppListItem

[out] Pointer to a pointer to an IXMLDOMNode interface. Returns NULL if the index is out of range. 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 to an IXMLDOMNodeList interface with the document's getElementsByTagName method. It then iterates 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;

if (bIsSuccessful)
{
    // 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(long i = 0; i < lCount; i++)
    {
        hr = pXMLNodeList->get_item(i, &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