IXMLDOMNamedNodeMap Object (C#)

banner art

Previous Next

IXMLDOMNamedNodeMap Object (C#)

The IXMLDOMNamedNodeMap object 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.

The IXMLDOMNamedNodeMap object supports the following property and methods.

Property Description
length Indicates the number of items in the collection. Read-only.
Method Description
getNamedItem Retrieves the attribute with the specified name.
getQualifiedItem* Returns the attribute with the specified namespace and attribute name.
item Allows random access to individual nodes within the collection. Read-only.
nextNode Returns 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.

  • Note   For detailed information about using the C++ programming language to access the IXMLDOMNamedNodeMap object, see the IXMLDOMNamedNodeMap interface.

Remarks

The IXMLNamedNodeMap object 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 objects to be maintained in any particular order. Objects contained in an IXMLDOMNamedNodeMap object 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 Code

The following example creates an IXMLDOMNamedNodeMap object and displays the number of attributes in a specific node.

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;

// Declare variables.
WMSServer Server;
IXMLDOMDocument Playlist;
IXMLDOMNodeList NodeList;
IXMLDOMNode node;
IXMLDOMNamedNodeMap namedNodeMap;

try {
    // Create a new WMSServer object.
    Server = new WMSServerClass();

    // Create a new playlist object.
    Playlist = Server.CreatePlaylist();

    // Load a sample playlist file.
    Playlist.load("file://c:\\wmpub\\wmroot\\simple.wsx");

    // Retrieve the first node that matches the query
    // and display the number of attributes in that node.
    NodeList = Playlist.getElementsByTagName("media");
    node = NodeList[0];
    namedNodeMap = node.attributes;
    MessageBox.Show(namedNodeMap.length.ToString());
}
catch (Exception e) {
    // TODO: Handle exceptions.
}

See Also

Previous Next