利用StringEscapeUtils来转义和反转义html/xml/javascript中的特殊字符

我们经常遇到html或者xml在Java程序中被某些库转义成了特殊字符。

例如:

各种逻辑运算符: > >= < <=

== 被转义成了 &amp;#x3D;&amp;#x3D;

解决方案:

使用apache commons-lang3下的StringEscapeUtils工具类

maven依赖:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
</dependency>

例子代码:

String xmlString = "...";
xmlString = StringEscapeUtils.unescapeXml(xmlString)
原文地址:https://www.cnblogs.com/davidgu/p/10120260.html