Class StreamParser.ElementIterator

java.lang.Object
org.jsoup.parser.StreamParser.ElementIterator
All Implemented Interfaces:
Iterator<Element>, NodeVisitor
Enclosing class:
StreamParser

final class StreamParser.ElementIterator extends Object implements Iterator<Element>, NodeVisitor
  • Field Details

  • Constructor Details

    • ElementIterator

      ElementIterator()
  • Method Details

    • reset

      void reset()
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Element>
      Throws:
      UncheckedIOException - if the underlying Reader errors during a read
    • next

      public Element next()
      Specified by:
      next in interface Iterator<Element>
      Throws:
      UncheckedIOException - if the underlying Reader errors during a read
    • maybeFindNext

      private void maybeFindNext()
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<Element>
    • head

      public void head(Node node, int depth)
      Description copied from interface: NodeVisitor
      Callback for when a node is first visited.

      The node may be modified (for example via Node.attr(String)), removed with Node.remove(), or replaced with Node.replaceWith(Node). If the node is an Element, you may cast it and access those methods.

      Traversal uses a forward cursor. After head() completes:

      • If the current node is still attached, traversal continues into its current children and then its following siblings. Nodes inserted before the current node are not visited.
      • If the current node was detached and another node now occupies its former sibling position, the node now at that position is not passed to head() again. Traversal continues from there: its children are visited, then the node is passed to NodeVisitor.tail(Node, int), then later siblings are visited.
      • If the current node was detached and no node occupies its former sibling position, the current node is not passed to tail(), and traversal resumes at the node that originally followed it.

      Traversal never advances outside the original root subtree. If the traversal root is detached during head(), traversal stops at the original root boundary.

      Specified by:
      head in interface NodeVisitor
      Parameters:
      node - the node being visited.
      depth - the depth of the node, relative to the root node. E.g., the root node has depth 0, and a child node of that will have depth 1.
    • tail

      public void tail(Node node, int depth)
      Description copied from interface: NodeVisitor
      Callback for when a node is last visited, after all of its descendants have been visited.

      This method defaults to a no-op.

      The node passed to tail() is the node at the current traversal position when the subtree completes. If head() replaced the original node, this may be the replacement node instead.

      Structural changes to the current node are not supported during tail().

      Specified by:
      tail in interface NodeVisitor
      Parameters:
      node - the node being visited.
      depth - the depth of the node, relative to the root node. E.g., the root node has depth 0, and a child node of that will have depth 1.