Here you can find the source of getElementsFirstLevel(String html)
private static List<Element> getElementsFirstLevel(String html)
//package com.java2s; /*/*from w w w. j a v a 2s .c o m*/ * SonarQube Redmine Plugin * Copyright (C) 2013 Patroklos PAPAPETROU and Christian Schulz * dev@sonar.codehaus.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import java.util.ArrayList; import java.util.List; public class Main { /** * Return the first level of the elements given a element Body. * Only the first level, not the children of these. */ private static List<Element> getElementsFirstLevel(String html) { Document docu = Jsoup.parse(html); List<Element> elements = new ArrayList<Element>(); for (Node node : docu.getAllElements()) { if (node instanceof Element && node.parentNode() != null && node.parentNode().equals(docu.body())) { elements.add((Element) node); } } return elements; } }