Package org.jsoup.nodes

Examples of org.jsoup.nodes.Element.select()


   */
  public String addClass(String content, String selector, List<String> classNames, int amount) {

    Element body = parseContent(content);
   
    List<Element> elements = body.select(selector);
    if (amount >= 0) {
      // limit to the indicated amount
      elements = elements.subList(0, Math.min(amount, elements.size()));
    }
   
View Full Code Here


   */
  public String wrap(String content, String selector, String wrapHtml, int amount) {

    Element body = parseContent(content);
   
    List<Element> elements = body.select(selector);
    if (amount >= 0) {
      // limit to the indicated amount
      elements = elements.subList(0, Math.min(amount, elements.size()));
    }
   
View Full Code Here

   */
  public String remove(String content, String selector) {

    Element body = parseContent(content);
   
    List<Element> elements = body.select(selector);
    if (elements.size() > 0) {
      for (Element element : elements) {
        element.remove();
      }
     
View Full Code Here

    boolean modified = false;
    for (Entry<String, String> replacementEntry : replacements.entrySet()) {
      String selector = replacementEntry.getKey();
      String replacement = replacementEntry.getValue();
     
      List<Element> elements = body.select(selector);
      if (elements.size() > 0) {
       
        // take the first child
        Element replacementElem = parseContent(replacement).child(0);
       
View Full Code Here

   */
  public List<String> text(String content, String selector) {

    Element body = parseContent(content);
   
    List<Element> elements = body.select(selector);
    List<String> texts = new ArrayList<String>();
   
    for (Element element : elements) {
      texts.add(element.text());
    }
View Full Code Here

   
    // selector for anchor with name attribute only
    String nameA = "a[name]:not([href])";
   
    // select all headings that have inner named anchor
    List<Element> headingsInnerA = body.select(StringUtil.join(
        concat(headNoIds, ":has(" + nameA + ")", true), ", "));
   
    boolean modified = false;
    for (Element heading : headingsInnerA) {
      List<Element> anchors = heading.select(nameA);
View Full Code Here

        modified = true;
      }
    }
   
    // select all headings that have a preceding named anchor
    List<Element> headingsPreA = body.select(StringUtil.join(
        concat(headNoIds, nameA + " + ", false), ", "));
   
    for (Element heading : headingsPreA) {
      Element anchor = heading.previousElementSibling();
      if (anchor != null) {
View Full Code Here

  public String ensureHeadingIds(String content, String idSeparator) {

    Element body = parseContent(content);
   
    // first find all existing IDs (to avoid generating duplicates)
    List<Element> idElems = body.select("*[id]");
    Set<String> ids = new HashSet<String>();
    boolean modified = false;
    for (Element idElem : idElems) {
     
      // fix all existing IDs - remove colon and other symbols which mess up jQuery
View Full Code Here

    }
   
    List<String> headNoIds = concat(HEADINGS, ":not([id])", true);
   
    // select all headings that do not have an ID
    List<Element> headingsNoId = body.select(StringUtil.join(headNoIds, ", "));
   
    if (!headingsNoId.isEmpty() || modified) {
      for (Element heading : headingsNoId) {
       
        String headingText = heading.text();
View Full Code Here

  public String fixTableHeads(String content) {

    Element body = parseContent(content);
   
    // select rows with <th> tags within <tbody>
    List<Element> tableHeadRows = body.select("table > tbody > tr:has(th)");
    if (tableHeadRows.size() > 0) {
      for (Element row : tableHeadRows) {
       
        // get the row's table
        Element table = row.parent().parent();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.