如何在 Java 中取消转义 HTML 字符实体?
问题描述:
基本上我想解码给定的 Html 文档,并替换所有特殊字符,例如 " "
-> " "
, ">"
-> ">"
.
Basically I would like to decode a given Html document, and replace all special chars, such as " "
-> " "
, ">"
-> ">"
.
在 .NET 中,我们可以使用 HttpUtility.HtmlDecode
.
In .NET we can make use of HttpUtility.HtmlDecode
.
Java 中的等效函数是什么?
What's the equivalent function in Java?
答
我使用了 Apache Commons StringEscapeUtils.unescapeHtml4() :
I have used the Apache Commons StringEscapeUtils.unescapeHtml4() for this:
取消转义包含实体的字符串转义为包含实际的 Unicode 字符对应于逃逸.支持HTML 4.0 实体.
Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.