Here you can find the source of findRootElement(Element element)
private static Element findRootElement(Element element)
//package com.java2s; //License from project: Open Source License import org.jsoup.nodes.Element; public class Main { private static Element findRootElement(Element element) { Element parent;// w w w . j a va 2 s. co m do { parent = element.parent(); if (parent == null) { return element; } element = parent; } while (parent != null); return null; } }