METHOD:  NodeList::reset

NodeList.reset( )

The reset method resets the iterator to the point before the first item in the collection, so the next call to the nextNode method will return the first node.

In the following example we load the 'currencies.xml' file and create a collection of all 'currency' nodes. The code then determines how many items are in the collection using the length property, and displays the text of the last node. The code then calls the reset method to reposition the iterator, and the nextNode method to return the first node in the list. The text of that node is also displayed.

XML:
<currencies>
   <currency>CHF Swiss Francs</currency>
   <currency>DEM German Deutsche Marks</currency>
   <currency>GBP United Kingdom Pounds</currency>
   <currency>JPY Japanese Yen</currency>
   <currency>USD United States Dollars</currency>
</currencies>

Code (JavaScript):
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("currencies.xml");

node_list = xml_doc.getElementsByTagName("currency");
n = node_list.length
curr_node = node_list.item(n-1);
document.write(curr_node.xml);
node_list.reset();
curr_node = node_list.nextNode();
document.write("<br>" + curr_node.xml);

Output:
USD United States Dollars
CHF Swiss Francs

This property is a Microsoft extension to the W3C DOM.



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information