The NodeList Interface

You have already used the NodeList interface attributes and methods in these examples! Both the getElementsByTagName() method and the childNodes attribute will create a NodeList. In fact, this list is a list of node objects that can be accessed using the item method of the NodeList interface.

The item() Method

This method takes an index as its argument and returns the node at that index position. Null is returned if the index is out of range. Remember, that the count starts at zero, as always.

The length Attribute

This returns an unsigned long integer indicating the number of nodes in the NodeList.

Get XML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.