DOM_NamedNodeMap

## 5. DOM_NamedNodeMap

The `DOM_NamedNodeMap` type provides access to an unordered map that premits nodes to be retrieved and set by their `nodeName`. The `attributes` member of a `DOM_Element` node type is a `DOM_NamedNodeMap` as are the `entities` and `notations` members of the `DOM_DocumentType` interface.

Example 2. Enumerating the attributes of an Element
This example illustrates how to enumerate and print each attribute of a `DOM_Element` node.

      for (idx = 0; i < elem->attributes->length; i++) {
      	DOM_Attr *attr = DOM_NamedNodeMap_item(elem->attributes, idx);
      	printf("%s='%s'\n", attr->nodeName, DOM_Node_getNodeValue(attr));
      }

### 5.1. The DOM_NamedNodeMap type

Synopsis

      #include <domc.h>

      typedef struct {
      	int length;
      	/* other members */
      } DOM_NamedNodeMap;

Description
The `DOM_NamedNodeMap` structure provides a `length` member containing the number of elements in the map. This member must never be modified.

The `DOM_NamedNodeMap_getNamedItem` function
Synopsis

      #include <domc.h>
      DOM_Node *DOM_NamedNodeMap_getNamedItem(DOM_NamedNodeMap *this, DOM_String *name);

Description
The `DOM_NamedNodeMap_getNamedItem` function returns the node associated with the `name` parameter or returnes NULL if there is no node by that name in the map.

The `DOM_NamedNodeMap_setNamedItem` function
Synopsis

      #include <domc.h>
      DOM_Node *DOM_NamedNodeMap_setNamedItem(DOM_NamedNodeMap *this, DOM_Node *arg);

Description
The `DOM_NamedNodeMap_setNamedItem` function puts the node `arg` into `this` map using it's `nodeName` member as key key. If a node with the same name already exists in the map it will be replaced with the new node and returned. If the replaced node will no longer be used it must be freed with `DOM_Document_destroyNode`.
Returns
If the new `DOM_Node` replaces an existing node the replaced node is returned. Otherwise NULL is returned.

The `DOM_NamedNodeMap_removeNamedItem` function
Synopsis

      #include <domc.h>
      DOM_Node *DOM_NamedNodeMap_removeNamedItem(DOM_NamedNodeMap *this, DOM_String *name);

Description
The `DOM_NamedNodeMap_removeNamedItem` function removes and returns the named item from `this` map or returns NULL if there is no node by that name in the map.

The DOM specifications require that attributes with default DTD values should be replaced by their default value when the attribute is removed. Currently DOMC does not support default DTD values.

The `DOM_NamedNodeMap_item` function
Synopsis

      #include <domc.h>
      DOM_Node *DOM_NamedNodeMap_item(DOM_NamedNodeMap *this, int index);

Description
The `DOM_NamedNodeMap_item` function returns the node in `this` list at `index` which starts from 0.
Returns
The node at the specified index or NULL if there is no such node.

Copyright 2003 Michael B. Allen <mballen@erols.com> Generated by CStyleX 0.1.1