【问题标题】:How to unescape HTML 5 entities in Java (')如何在 Java (') 中取消转义 HTML 5 实体
【发布时间】:2021-06-20 17:18:40
【问题描述】:

this question 的答案大多建议使用 apache-common-text StringEscapeUtils。但是这个(commons-text 的最新版本是 1.9)只支持 HTML 4 和 Mastodon appears to use HTML 5,其中包括 '。如何解码 HTML 5 实体,包括 '

【问题讨论】:

  • 很抱歉问的很明显,但是您是否尝试过其他答案中给出的 other 建议?
  • @FedericoklezCulloca 好吧,我想使用一个相当标准的库和/或标准 Java API如果有的话。我还想知道为什么 Apache 不支持 HTML 5 实体,或者我只是缺少更新版本的库。

标签: java html apache-commons html-entities


【解决方案1】:

unbescape 做得很好:

final String unescapedText = HtmlEscape.unescapeHtml("'");
System.out.println(unescapedText);

结果:

'

马文:

<!-- https://mvnrepository.com/artifact/org.unbescape/unbescape -->
<dependency>
    <groupId>org.unbescape</groupId>
    <artifactId>unbescape</artifactId>
    <version>1.1.6.RELEASE</version>
</dependency>

【讨论】:

    猜你喜欢
    • 2018-08-16
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    相关资源
    最近更新 更多