Share via


IXMLDOMNamedNodeMap::getNamedItem

banner art

Previous Next

IXMLDOMNamedNodeMap::getNamedItem

The getNamedItem method retrieves the attribute with the specified name.

Syntax

  HRESULT getNamedItem(
 BSTR bstrName,
 IXMLDOMNode** ppNamedItem
);

Parameters

bstrName

[in] BSTR containing the name of the attribute.

ppNamedItem

[out] Pointer to a pointer an IXMLDOMNode interface for the specified attribute. This is set to NULL if the attribute node is not in this collection. 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 bstrName does not correspond to any name in the collection, the method returns S_FALSE and sets ppNamedItem to NULL. If it fails, it returns an HRESULT error code.

Example Code

The following example uses the getNamedItem method to retrieve an attribute node named "src".

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

// Declare variables.
IWMSServer*          pServer;
IXMLDOMDocument*     pPlaylist;
IXMLDOMElement*      pXMLElement;
IXMLDOMNamedNodeMap* pXMLNamedNodeMap;
IXMLDOMNode*         pChildNode;
IXMLDOMNode*         pXMLNode;
IXMLDOMNodeList*     pChildList;

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

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

    // Retrieve a list of the child nodes.
    hr = pXMLElement->get_childNodes(&pChildList);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the first child in the list.
    hr = pChildList->get_item(0, &pChildNode);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the list of attributes.
    hr = pXMLNode->get_attributes(&pXMLNamedNodeMap);
    if (FAILED(hr)) goto EXIT;

    // Retrieve an attribute named "src".
    bstrName = "src";
    hr = pXMLNamedNodeMap->getNamedItem(bstrName, &pXMLNode);
    if (FAILED(hr)) goto EXIT;
}

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