Java 用JSoup连接HTML元素

Java 用JSoup连接HTML元素,java,html,tags,jsoup,element,Java,Html,Tags,Jsoup,Element,在JSoup中是否有任何方法可以连接内存中的两个或多个元素,即在文档树中,而不产生原始HTML字符串 例如,下面的HTML div元素包含一些嵌套的标记 <div>This is text with <custom>a custom nested tag</custom> and some <other>text within a tag</other>, all of which should become part of the t

在JSoup中是否有任何方法可以连接内存中的两个或多个元素,即在文档树中,而不产生原始HTML字符串

例如,下面的HTML div元素包含一些嵌套的标记

<div>This is text with <custom>a custom nested tag</custom> and some <other>text within a tag</other>, all of which should become part of the top-level </div>.

Jsoup的函数就是您要寻找的。它将删除元素,但保留子元素。

请尝试展开感谢和+1。如果你在答复中提出这一意见,我将接受。
<div>This is text with a custom nested tag and some text within a tag, all of which should become part of the top-level </div>.
public static method splice(Document document, List<String> tags) {
  for (String tag : tags) {
    // Find the tag node (Element) in the tree
    // Remove the tag node and join its content with its parent
  }
}