Java Code Examples for org.jsoup.nodes.Element#empty()
The following examples show how to use
org.jsoup.nodes.Element#empty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextFilterManage.java From bbs with GNU Affero General Public License v3.0 | 5 votes |
/** * 处理隐藏标签 * @param html 富文本内容 * @param visibleTagList 允许可见的隐藏标签 * @return */ public String processHiddenTag(String html,List<Integer> visibleTagList){ if(!StringUtils.isBlank(html)){ Document doc = Jsoup.parseBodyFragment(html); Elements elements = doc.select("hide"); for (Element element : elements) { //隐藏标签类型 String hide_type = element.attr("hide-type"); //隐藏标签输入值 // String input_value = element.attr("input-value"); if(visibleTagList.contains(Integer.parseInt(hide_type.trim()))){//如果允许可见 /** //替换当前标签为<p>标签 element.removeAttr("class"); element.removeAttr("hide-type"); element.removeAttr("input-value"); element.tagName("p");**/ //移除匹配的元素但保留他们的内容 element.unwrap(); }else{ if(hide_type.trim().equals(HideTagType.PASSWORD.getName().toString())){//输入密码可见 element.removeAttr("input-value"); } //清空元素的内容 element.empty(); } } //prettyPrint(是否重新格式化)、outline(是否强制所有标签换行)、indentAmount(缩进长度) doc.outputSettings().indentAmount(0).prettyPrint(false); doc.outputSettings().prettyPrint(false); html = doc.body().html(); } return html; }
Example 2
Source File: Elements.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Empty (remove all child nodes from) each matched element. This is similar to setting the inner HTML of each * element to nothing. * <p> * E.g. HTML: {@code <div><p>Hello <b>there</b></p> <p>now</p></div>}<br> * <code>doc.select("p").empty();</code><br> * HTML = {@code <div><p></p> <p></p></div>} * @return this, for chaining * @see Element#empty() * @see #remove() */ public Elements empty() { for (Element element : this) { element.empty(); } return this; }
Example 3
Source File: Elements.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Empty (remove all child nodes from) each matched element. This is similar to setting the inner HTML of each * element to nothing. * <p> * E.g. HTML: {@code <div><p>Hello <b>there</b></p> <p>now</p></div>}<br> * <code>doc.select("p").empty();</code><br> * HTML = {@code <div><p></p> <p></p></div>} * @return this, for chaining * @see Element#empty() * @see #remove() */ public Elements empty() { for (Element element : this) { element.empty(); } return this; }
Example 4
Source File: Elements.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Empty (remove all child nodes from) each matched element. This is similar to setting the inner HTML of each * element to nothing. * <p> * E.g. HTML: {@code <div><p>Hello <b>there</b></p> <p>now</p></div>}<br> * <code>doc.select("p").empty();</code><br> * HTML = {@code <div><p></p> <p></p></div>} * @return this, for chaining * @see Element#empty() * @see #remove() */ public Elements empty() { for (Element element : this) { element.empty(); } return this; }
Example 5
Source File: Elements.java From jsoup-learning with MIT License | 3 votes |
/** * Empty (remove all child nodes from) each matched element. This is similar to setting the inner HTML of each * element to nothing. * <p> * E.g. HTML: {@code <div><p>Hello <b>there</b></p> <p>now</p></div>}<br> * <code>doc.select("p").empty();</code><br> * HTML = {@code <div><p></p> <p></p></div>} * @return this, for chaining * @see Element#empty() * @see #remove() */ public Elements empty() { for (Element element : contents) { element.empty(); } return this; }