Jsoup 没有替换文档内容

Jsoup is not replacing document content

这里我在 mailFormat.getBody() 中存储 html 内容现在在邮件格式中 我想用存储在 (String) res.get("name") 和 [= 中的指定名称替换 span#userName 的文本14=] 的文本带有 getPassword()System.out.println(usrName + " " + passwd+" "+mailFormat.getBody()); 行显示已替换的用户名和密码,但未在 mailFormat.getBody() 处更新。 我的代码片段如下。

Jsoup 未更新基础文档 mailFormat.getBody()

 Document doc = Jsoup.parse(mailFormat.getBody());
 Elements elms = doc.select("span#userName");
 Element usrName = doc.select("span#userName").first();
 System.out.println((String) res.get("name") + " " + getPassword() + " el " + usrName);
 usrName.text((String) res.get("name"));
 Element passwd = doc.select("span#password").first();
 passwd.text((String) getPassword());
 System.out.println(usrName + "  " + passwd+" "+mailFormat.getBody());

如何解决?

saka1029找到的解决方案:

Your code only replace doc. You should push it back to mailFormat.