Reputation: 49
Is there any way how to escape in Java characters in string which contains html tags which i want not to escape? For example in string I have
<h1>a b c d ö</h1>
and I need to get:
<h1>a b c d ö</h1>
Upvotes: 2
Views: 2354
Reputation: 11
Check this:
String textIn = "<h1>a b c d ö</h1>";
String textOut = StringEscapeUtils.escapeHtml4(textIn);
println textOut: <h1>a b c d ö</h1>
For xml or tags:
String textIn = "<h1>a b c d ö</h1>";
String textOut = StringEscapeUtils.unescapeXml(StringEscapeUtils.escapeHtml4(textIn));
println: textOut <h1>a b c d ö</h1>
Upvotes: 1
Reputation: 4942
See:
public static void main(String[] args) {
String s = "a b c d ö";
System.out.println(StringEscapeUtils.escapeHtml4(s));
}
Upvotes: 0