The get_length method indicates the number of items in the IXMLDOMNodeList collection.

HRESULT get_length(
long* lListLength



[out] Pointer to a long representing the number of items in the collection.

Return Value

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


The following example retrieves a pointer to an IXMLDOMNodeListIXMLDOMNodeList Interface and then uses its get_length method to support iteration.

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

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

HRESULT               hr;
CComVariant           varAttValue;
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 the node name "media".
    bstrName = "media";
    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;

    // Display node value associated with each node 
    // in the collection.
    for (int i = 0; i < lCount; i++)
        hr = pXMLNodeList->get_item(i, &pXMLNode);
        if (FAILED(hr)) goto EXIT;
        hr = pXMLNode->get_nodeValue(&varAttValue);
        if (FAILED(hr)) goto EXIT;

        // Release temporary COM objects.

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


IXMLDOMNodeList Interface


XML DOM Methods (C++)