简体   繁体   English

使用Jsoup Element.text()时在块元素后添加空格

[英]Add whitespace after block elements when using Jsoup Element.text()

The following: 下列:

Jsoup.parse("<h1>Heading</h1>Bodytext").text()

gives "HeadingBodytext" - ie with no whitespace added at the end of a block level element. 给出“ HeadingBodytext”-即在块级元素的末尾没有添加空格。 Is there a workaround to add this whitespace in myself? 有没有在我自己中添加此空格的解决方法? Ideally it would happen for every block level element. 理想情况下,它将发生在每个块级元素中。

Little dirty, but cant help: 有点脏,但不能帮助:

String t = Jsoup.parse("<h1>Heading</h1>Bodytext").select("h1").first().ownText();

This will return own text of h1 tag, so you can add whitespace and the rest of string. 这将返回自己的h1标签文本,因此您可以添加空格和其余字符串。

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

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