如何在 Java 中取消转义 HTML 字符实体? [英] How to unescape HTML character entities in Java?

查看:47
本文介绍了如何在 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.

这篇关于如何在 Java 中取消转义 HTML 字符实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆