001package org.jsoup.select; 002 003import org.jsoup.nodes.Node; 004 005/** 006 * Node visitor interface. Provide an implementing class to {@link NodeTraversor} to iterate through nodes. 007 * <p> 008 * This interface provides two methods, {@code head} and {@code tail}. The head method is called when the node is first 009 * seen, and the tail method when all of the node's children have been visited. As an example, head can be used to 010 * create a start tag for a node, and tail to create the end tag. 011 * </p> 012 */ 013public interface NodeVisitor { 014 /** 015 * Callback for when a node is first visited. 016 * 017 * @param node the node being visited. 018 * @param depth the depth of the node, relative to the root node. E.g., the root node has depth 0, and a child node 019 * of that will have depth 1. 020 */ 021 void head(Node node, int depth); 022 023 /** 024 * Callback for when a node is last visited, after all of its descendants have been visited. 025 * 026 * @param node the node being visited. 027 * @param depth the depth of the node, relative to the root node. E.g., the root node has depth 0, and a child node 028 * of that will have depth 1. 029 */ 030 void tail(Node node, int depth); 031}