Share via


IXMLDOMNamedNodeMap Interface

The IXMLDOMNamedNodeMap interface supports iteration through the collection of attribute nodes. 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 IXMLDOMNamedNodeMap 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.

getNamedItem

Retrieves the attribute with the specified name.

getQualifiedItem*

Retrieves the attribute with the specified namespace and attribute name.

nextNode

Retrieves the next node in the collection.

removeNamedItem

Removes an attribute from the collection.

removeQualifiedItem

Removes the attribute with the specified namespace and attribute name.

reset

Resets the iterator in the collection of attribute nodes.

setNamedItem

Adds the supplied node to the collection.

* Denotes an extension to the W3C DOM.

Remarks

The IXMLNamedNodeMap interface is a node collection that allows access by name as well as by index. This collection is typically used for attributes.

The World Wide Web Consortium (W3C) Document Object Model (DOM) definition does not require IXMLDOMNamedNodeMap interfaces to be maintained in any particular order. Interfaces retrieved from an IXMLDOMNamedNodeMap interface can also be accessed by an ordinal index, but this is simply to allow convenient enumeration and does not imply that the DOM specifies an order to these nodes. DOM implementations are not required to preserve the node order.

The Microsoft implementation preserves the attributes in the order in which they appear in the source. Additional attributes are added to the end of the list.

Like the node list, however, a named node map 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 IXMLDOMNamedNodeMap interface and retrieves the total number of attributes in the node collection.

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

// Declare variables.
IWMSServer*           pServer;
IXMLDOMDocument*      pPlaylist;
IXMLDOMElement*       pXMLElement;
IXMLDOMNamedNodeMap*  pXMLNamedNodeMap;

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

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

    // Retrieve a pointer to the IXMLDOMNamedNodeMap interface.
    hr = pXMLElement->get_attributes(&pXMLNamedNodeMap);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the total count of attributes.
    hr = pXMLNamedNodeMap->get_length(&lCount);
    if (FAILED(hr)) goto EXIT;
}

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

See Also

Concepts

Programming Reference (C++)