Help Center

Local Navigation

Object: NamedNodeMap

Availability

BlackBerry® Device Software version 4.6 or later

The NamedNodeMap object represents collections of nodes that can be accessed by name.

You can access an individual node within a collection by its index position using NamedNodeMap.item(), by its name or id attribute using NamedNodeMap.getNamedItem(), or you can index the object directly. For example, if you create an instance of a NamedNodeMap object called myNamedNodeMap, then specifying

myNamedNodeMap.item(2)

myNamedNodeMap.getNamedItem(“item”)

is equivalent to specifying

myNamedNodeMap[2]

myNamedNodeMap[“item”]

NamedNodeMap properties

Property name

Type

Description

Status

Availability

length

unsigned long

Returns the number of nodes in the map.

read only

4.6 or later

NamedNodeMap methods

Method name

Description

Availability

getNamedItem()

Retrieves the node with the given name.

4.6 or later

getNamedItemNS()

Retrieves the node with the given name and namespace URI.

4.6 or later

item()

Returns the node at the given index in the map.

4.6 or later

removeNamedItem()

Removes the node with the given name from the map.

4.6 or later

removeNamedItemNS()

Removes the node with the given name and namespace URI from the map.

4.6 or later

setNamedItem()

Adds a node using the Node.nodeName attribute.

4.6 or later

setNamedItemNS()

Adds a node using the Node.nodeName attribute and the namespace URI.

4.6 or later

Method: NamedNodeMap.getNamedItem()

Availability

BlackBerry® Device Software version 4.6 or later

The getNamedItem() method retrieves the node with the given name.

Syntax

NamedNodeMap.getNamedItem( name )

Parameters

Parameter

Type

Description

name

String

The value of the Node.nodeName property of the node to retrieve.

Return values

Returns the node with a Node.nodeName value of name, or null if the given parameter does not identify any existing node in the map.

Exceptions

None.

Method: NamedNodeMap.getNamedItemNS()

Availability

BlackBerry® Device Software version 4.6 or later

The getNamedItemNS() method retrieves the node with the specified name and namespace URI.

Syntax

NamedNodeMap.getNamedItemNS( namespaceURI, localName )

Parameters

Parameter

Type

Description

namespaceURI

String

The namespace of the node to retrieve.

localName

String

The local name of the node to retrieve.

Return values

Returns the node with the given local name and namespace URI, or null if the given parameters do not identify any existing node in the map.

Exceptions

Exception

Description

NOT_SUPPORTED_ERR

This error is thrown if the document does not support XML namespaces.

Method: NamedNodeMap.item()

Availability

BlackBerry® Device Software version 4.6 or later

The item() method returns the node at the specified index in the map.

Syntax

NamedNodeMap.item( index )

Parameters

Parameter

Type

Description

index

int

An integer that represents the node’s position in the node map. Valid values are between 0 and NamedNodeMap.length-1 inclusive.

Return values

Returns the node at the indexth position in NamedNodeMap, or null if an invalid index position is specified.

Exceptions

None.

Method: NamedNodeMap.removeNamedItem()

The removeNamedItem() method removes the node with the specified name from the map.

If you are removing an Attr node from the NamedNodeMap.length object that is known to have a default value, the removed Attr will immediately be reattached to the element with its default value, as well as its corresponding namespace URI, local name, and prefix, if applicable.

Syntax

NamedNodeMap.removeNamedItem( name )

Parameters

Parameter

Type

Description

name

String

The value of Node.nodeName property of the node to remove.

Return values

Returns the removed Node object, if it exists.

Exceptions

Exception

Description

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the NamedNodeMap object is read only.

NOT_FOUND_ERR

This error is thrown if no node with a Node.nodeName value of name exists in the NamedNodeMap.

Method: NamedNodeMap.removeNamedItemNS()

Availability

BlackBerry® Device Software version 4.6 or later

The removeNamedItemNS() method removes the node with the specified name and namespace URI from the map.

If you are removing an Attr node from the NamedNodeMap object that is known to have a default value, the Attr will immediately be reattached to the element with its default value, as well as its corresponding namespace URI, local name, and prefix, if applicable.

Syntax

NamedNodeMap.removeNamedItemNS( namespaceURI, localName )

Parameters

Parameter

Type

Description

namespaceURI

String

The namespace of the node to remove.

localName

String

The local name of the node to remove.

Return values

Returns the removed Node object, if it exists.

Exceptions

Exception

Description

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the NamedNodeMap object is read only.

NOT_FOUND_ERR

This error is thrown if no node with a Node.nodeName value of name exists in the NamedNodeMap.

NOT_SUPPORTED_ERR

This error is thrown if the document does not support XML namespaces.

Method: NamedNodeMap.setNamedItem()

The setNamedItem() method adds a node to the node map using the Node.nodeName property. If a node with the same Node.nodeName value already exists in the map, the existing node is removed and is replaced by the new node and the removed node is returned.

As the Node.nodeName property is used to store the new node in the map, in order to prevent name clashes, you may not add multiple nodes of those node types that always have the same Node.nodeName value. For example, a text node will always have a Node.nodeName value of #text. Therefore, only a single text node may be included in any NamedNodeMap object.

Syntax

NamedNodeMap.setNamedItem( arg )

Parameters

Parameter

Type

Description

arg

Node

The node to add to the map.

Return values

If the new node has replaced an existing node, returns the removed node; otherwise returns null.

Exceptions

Exception

Description

HIERARCHY_REQUEST_ERR

This error is thrown if the arg node is not permitted in this NamedNodeMap, for example, if you tried to insert a node other than an Attr into an Element’s map of attributes.

INUSE_ATTRIBUTE_ERR

This error is thrown if arg is an Attr object that is already an attribute of another Element object. To add an attribute used elsewhere, you must clone it, and then add it.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the NamedNodeMap object is read only.

WRONG_DOCUMENT_ERR

This error is thrown if arg was created from a different document than the one that created this NamedNodeMap object.

Method: NamedNodeMap.setNamedItemNS()

The setNamedItemNS() method adds a node using the Node.nodeName property and the namespace URI.

Syntax

NamedNodeMap.setNamedItemNS( arg )

Parameters

Parameter

Type

Description

arg

Node

The node to add to the map.

Return values

If the new node has replaced an existing node, returns the removed node; otherwise returns null.

Exceptions

Exception

Description

HIERARCHY_REQUEST_ERR

This error is thrown if the arg node is not permitted in this NamedNodeMap, for example, if you tried to insert a node other than an Attr into an Element’s map of attributes.

INUSE_ATTRIBUTE_ERR

This error is thrown if arg is an Attr object that is already an attribute of another Element object. To add an attribute used elsewhere, you must clone it, and then add it.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the NamedNodeMap object is read only.

NOT_SUPPORTED_ERR

This error is thrown if the document does not support XML namespaces.

WRONG_DOCUMENT_ERR

This error is thrown if arg was created from a different document than the one that created this NamedNodeMap object.

Next topic: Object: Navigator

Was this information helpful? Send us your comments.