Chapter 3 DynaScript Predefined Objects
Represents a collection of DOMNode objects that can be accessed by name.
To use a DOMNamedNodeMap's property:
DOMNamedNodeMap.propertyName
To use a DOMNamedNodeMap's method:
DOMNamedNodeMap.MethodName( parameter )
DOMNamedNodeMap
objects
represent an unordered collection of DOMNode
objects.
Objects within the node map can be accessed by an ordinal index,
but this is simply provided as a means of enumerating the objects
within the node map. It does not imply that the objects within the
node map are ordered.
DOMNamedNodeMap.length
The number of objects in the map.
This example loops over the items of a DOMNamedNodeMap
object.
for ( i = 0; i < nodemap.length; i++ ){ // operations here }
DOMNamedNodeMap.getNamedItem( name )
Retrieves a DOMNode
specified
by name.
A DOMNode
object
or null if the specified name did not identify any node in the map
This example creates a DOMNamedNodeMap
named attlist from
the attributes
property
of an element, and then writes out the value of the attribute with
name attName:
attlist = elem.attributes att = attlist.getNamedItem( attName ); document.writeln( att.value );
DOMNamedNodeMap.item( index )
Returns the index item in the map. If index is greater than or equal to the number of nodes in the map, null is returned. Valid values for index are 0 through length minus one.
A DOMNode
object
or null if the index is invalid
This script fragment loops over the items of
a DOMNamedNodeMap
object
and assigns each node to a variable named thisNode:
for ( i = 0; i < nodemap.length; i++ ){ thisNode = nodemap.item( i ); }
DOMNamedNodeMap.removeNamedItem( name )
Removes a DOMNode
object
specified by name.
The DOMNode
object
that was removed, or null if the specified name did not identify
any node in the map
This example removes the attribute named attType from each Region element, and prints out messages for debugging purposes:
function RemoveNamedItem( domDoc, attType ){ elemlist = domDoc.getElementsByTagName( "Region" ) for( iElem=0; iElem < elemlist.length; iElem++ ) { elem = elemlist.item( iElem ); attlist = elem.attributes node = attlist.removeNamedItem( attType ); if( node == null ) { document.writeln( "No attribute removed" ); } else { document.writeln( "Removed attribute with value" + node.nodeValue ); } } document.writeln( domDoc.prettyPrint() ); }
DOMNamedNodeMap.setNamedItem( node-name )
Adds a node using its nodeName
property.
The node-name parameter is a DOMNode
object
to be stored in the named node map. The node will later be accessible
using the value of the node's nodeName property passed
to the getNamedItem
method.
If the new node replaces an existing node with
the same name, the previously existing node is returned as a DOMNode
object,
otherwise null is returned.
This example replaces an attribute node with one of the same name, but a changed value.
function SetNamedItem( domDoc, attType ){ elemlist = domDoc.getElementsByTagName( "Region" ) for( iElem=0; iElem < elemlist.length; iElem++ ) { elem = elemlist.item( iElem ); attlist = elem.attributes att = attlist.getNamedItem( attType ); att.value = "County"; oldNode = attlist.setNamedItem( att.name ); if( oldNode == null ) { document.writeln( "New attribute added" ); } else { document.writeln( "Replaced attribute" ); } } }
Copyright © 2001 Sybase, Inc. All rights reserved. |
![]() |