如何在 Jsoup 中编写 & 字符
我正在使用 Jsoup 来解析和修改一些 HTML。在某些地方,我想向 HTML 添加不间断空格实体 ( )。我以为我可以像这个简化的例子一样做到这一点:
Element paragraph = someDocument.select("p").first();
paragraph.text("First sentence. Second sentence.");
但是 Jsoup 将我的
转换为
有效地编码&符号本身。我想我真正的问题是:如何手动将 & 符号写入 Element
的文本?
I'm using Jsoup to parse and modify some HTML. In certain places, I want to add a non-breaking space entity ( ) to the HTML. I assumed I could do it as in this simplified example:
Element paragraph = someDocument.select("p").first();
paragraph.text("First sentence. Second sentence.");
But Jsoup turns my
into
effectively encoding the ampersand itself. I guess my real question is: how can I manually write an ampersand character to the text of an Element
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你正在做Element.text。如果是 html,请使用 .html(String s) 代替,将代码替换为
You are doing Element.text. If its html, use .html(String s) instead so, replace your code with
尝试使用 unicode 值作为不间断空格。
Try using the unicode value for no-breaking space.