Here you can find the source of removeTag(String html)
input:The output, can managing by #newOutputSetting(Document.OutputSettings)I amoutput: I amJava
programmerJava
programmer
Parameter | Description |
---|---|
html | input html |
public static String removeTag(String html)
//package com.java2s; //License from project: Open Source License import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class Main { private static Document.OutputSettings setting; /**//from w w w . j a va 2 s.com * remove top tag and return as string <br> * <pre>{@code * input: <div>I am <code>Java</code> programmer</div> * output: I am <code>Java</code> programmer * }</pre> * <b>The output, can managing by {@link #newOutputSetting(Document.OutputSettings)}</b> * * @param html * input html * @return string that removed top tag */ public static String removeTag(String html) { return parse(html).child(0).html(); } /** * remove top tag and return as string <br> * <b>The output, can managing by {@link #newOutputSetting(Document.OutputSettings)}</b> * * @param html * input Elements (easy get from {@link #getHtmlInTag(String, String)}) * @return string that removed top tag * @see #removeTag(String) */ public static String removeTag(Elements html) { return parse(html.toString()).child(0).html(); } /** * convert html String to {@link Document} (A lot more easier to manage it) * * @param html * input html * @return Document (include html body and head Tag) * @see Document * @see Document#head() * @see Document#body() */ public static Document parse(String html) { Document document = Jsoup.parse(html); if (setting != null) return document.outputSettings(setting); return document; } }