Chapter 3 DynaScript Predefined Objects
The DOMNamedNodeMap
object
has these methods:
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 - 1.
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 © 1999 Sybase, Inc. All rights reserved. |
![]() |