简体   繁体   English

使用jsoup删除两个标签之间的html文本

[英]Removing html text between two tags with jsoup

I would like to remove HTML text between two tags recursively like <bloquotes><bloquotes>一样递归地删除两个标签之间的 HTML 文本

For this example:对于这个例子:

<div>hfhfk
<bloquotes><bloquotes>ppppp</bloquotes>fin texte </bloquotes>
</div>

I'd like to have the following result:我想得到以下结果:

<div>hfhfk</div>

Using jQuery you could do this:使用 jQuery 你可以这样做:

$("bloquotes").each(function(){
       $(this).html("");
});
$("bloquotes").remove();

Here you are:这个给你:

String html = "<div>hfhfk<bloquotes><bloquotes>ppppp</bloquotes>fin texte </bloquotes></div>";
Document doc = Jsoup.parse(html);

Elements source = doc.select("div");
Element element = (Element) source.get(0);
Node result = element.childNode(0);
String nodeResult = result.toString().trim();

System.out.println(nodeResult + "");
System.out.println(nodeResult.length() + "");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM