ompratap
ompratap

Reputation: 9

Unable to unesape consecutive escape char in org.apache.commons.lang3.StringEscapeUtils.unescapeXml()

Unable to unescape consecutive escape char like <errors>. Below is the sample code:

    String error = "<errors>";
    String out = org.apache.commons.lang3.StringEscapeUtils.unescapeXml(error);
    System.out.println(out);

Current Output: <errors>

Expected output: <errors>

This code ran on JDK 11.0.16 version and commons-lang3-3.4.jar version.

Upvotes: 0

Views: 126

Answers (1)

Bombe
Bombe

Reputation: 83983

You need to unescape the String as many times as the input String has been escaped.

var input = "&amp;lt;errors&amp;gt;";
var output = StringEscapeUtils.unescapeXml(input);
output = StringEscapeUtils.unescapeXml(output);
System.out.println(output);

Upvotes: 0

Related Questions