@Test public void traverse() {

    Document doc = Jsoup.parse("<div><p>Hello</p></div><div>There</div>");
    final StringBuilder accum = new StringBuilder();
    doc.select("div").first().traverse(new NodeVisitor() {
        public void head(Node node, int depth) {
            accum.append("<" + node.nodeName() + ">");
        }
        public void tail(Node node, int depth) {
            accum.append("</" + node.nodeName() + ">");
        }
    });
    assertEquals("<div><p><#text></#text></p></div>", accum.toString());
}