Java HTML Jsoup Element getElementsFirstLevel(String html)

Here you can find the source of getElementsFirstLevel(String html)

Description

Return the first level of the elements given a element Body.

License

Open Source License

Declaration

private static List<Element> getElementsFirstLevel(String html) 

Method Source Code


//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;
    }
}

Related

  1. getCodeSnippetCLT(Element codeElement, String content, String fqn, String api, String kind, String[] titles)
  2. getDate(Elements caption)
  3. getDouble(Elements line, int idx)
  4. getElementByXPath(String xpath, Document doc)
  5. getElementsByClass(String className, Element boardElement)
  6. getElementTextBySelector(String html, String selector)
  7. getElementValue(Element wrapperElement, String cssQuery)
  8. getElIndexInSameTags(Element e)
  9. getFirstWithOwnText(final Elements elementList, final String text)