NodeList and NamedNodeMap

We have encountered two other interesting interfaces, but we have not yet examined them in detail—NodeList and NamedNodeMap. These two interfaces exist to process lists of nodes and are surprisingly similar. NodeList is the simpler of the two, and we will start with it.

NodeList

NodeList has two methods of interest:

  • int getLength() Returns the count of nodes within the list

  • Node item(int index) Returns the Node at index

Otherwise, a NodeList is straightforward. One other important aspect of a NodeList is that the Nodes are returned in the order in which they are specified in the XML or in the order they were specified when added to the parent node.

NamedNodeMap

NamedNodeMap is similar to NodeList and, in fact, contains ...

Get XML Development with Java™ 2 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.