Interface NodeIterator

All Superinterfaces:
Iterator<Node>, ListIterator<Node>

public interface NodeIterator extends ListIterator<Node>
Iterates over the document nodes according to a set of parameters.


This interface is based on the NodeIterator interface in DOM Level 4, although behaviour does not exactly match:

Iterators implementing this interface are expected to skip full nodes (descendants included) when the NodeFilter returns NodeFilter.FILTER_SKIP_NODE_CHILD, while the W3C standard would expect it to behave like NodeFilter.FILTER_SKIP (which in this implementation is called NodeFilter.FILTER_SKIP_NODE), and skip only the node itself.

Additionally, beware that this iterator also behaves differently from the Xerces NodeIterator regarding attributes:

  1. Attributes do not always follow the specified order in Xerces.
  2. Its iterator of attributes only traverses the root node.

If the filtering done by the NodeFilter changes during the traversal (that is, nodes that were previously accepted now aren't), the behaviour of this iterator may become inconsistent when going backwards. In that case, you may want to try a TreeWalker instead.

ListIterator optional operations: add, set, remove

This library's iterator implements ListIterator and its optional operations, but any attempts to remove the root node, to change it with set (or to insert a node before it with add) must fail.

  • Method Details

    • getRoot

      DOMNode getRoot()
      The root node to iterate.

      See the description of root in DOM Level 4.

      the root node.
    • getWhatToShow

      int getWhatToShow()
      The bitmask specifying what types of nodes to show.
      the bitmask to control which types of nodes are returned by the iterator.
    • getNodeFilter

      NodeFilter getNodeFilter()
      Get the NodeFilter callback.

      See NodeFilter.

      a reference to the NodeFilter callback.
    • next

      DOMNode next()
      Specified by:
      next in interface Iterator<Node>
      Specified by:
      next in interface ListIterator<Node>
    • nextNode

      DOMNode nextNode()
      The same as next(), but avoids the NoSuchElementException. Exists for compatibility with the NodeIterator in DOM Level 4.
      the next node, or null if there is no next node.
    • previous

      DOMNode previous()
      Specified by:
      previous in interface ListIterator<Node>
    • previousNode

      DOMNode previousNode()
      The same as previous(), but avoids the NoSuchElementException. Exists for compatibility with the NodeIterator in DOM Level 4.
      the previous node, or null if there is no previous node.