Here you can find the source of findAllNodesBefore(Element firstChapter)
public static List<Node> findAllNodesBefore(Element firstChapter)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; public class Main { public static List<Node> findAllNodesBefore(Element firstChapter) { List<Node> foundNodes = new ArrayList<>(); List<Node> parentNodes = getAllNodes(firstChapter.parent()); for (Node node : parentNodes) { if (node instanceof Element) { Element element = (Element) node; if ("h1".equals(element.tagName())) { return foundNodes; }//from www . jav a2s . c o m } foundNodes.add(node); } return foundNodes; } public static List<Node> getAllNodes(Element element) { try { Field childNodesField = Node.class.getDeclaredField("childNodes"); childNodesField.setAccessible(true); @SuppressWarnings("unchecked") List<Node> childNodes = (List<Node>) childNodesField.get(element); return childNodes; } catch (Exception e) { throw new RuntimeException("Could not get the nodes of element: " + element, e); } } }