Jsoup.clean无需添加html实体
我正在使用清除不需要的HTML标签(例如<script>)中的一些文本
String clean = Jsoup.clean(someInput, Whitelist.basicWithImages());问题是,它取代例如å用å(这会导致麻烦的我,因为它不是“纯XML”)。
例如
Jsoup.clean("hello å <script></script> world", Whitelist.basicWithImages())产量
"hello å world"但我想
"hello å world"有没有简单的方法可以做到这一点?(即比转换å回å结果更简单。)
回答:
您可以配置Jsoup的转义模式:使用EscapeMode.xhtml将为您提供无实体输出。
这是一个完整的代码段,可以接受str作为输入,并使用进行清理Whitelist.simpleText():
// Parse str into a DocumentDocument doc = Jsoup.parse(str);
// Clean the document.
doc = new Cleaner(Whitelist.simpleText()).clean(doc);
// Adjust escape mode
doc.outputSettings().escapeMode(EscapeMode.xhtml);
// Get back the string of the body.
str = doc.body().html();
以上是 Jsoup.clean无需添加html实体 的全部内容, 来源链接: utcz.com/qa/414868.html


