如何修改jsoup中的html文件内容?

How to modify the html file content in jsoup?

我有一个如下所示的 html 文件

<div id ="test"> <u>s</u> </div>  

我想这样修改 java

  <div id ="test"> <b>Test<b> </div>

在 jsoup 中可以吗?

有可能:

  Element el = doc.select("div#test").first();
  for (Element elC : el.children()) {
      elC.remove();
  }
  Element nel = el.appendElement("b");
  nel.text("Test");