Unescaping Html tags

We often face some issues while handling the HTML tags in Java. Consider the below example.


import org.apache.commons.lang3.StringEscapeUtils;

public class StringUtils {

    public static void main(String[] args) {

        String content = "5 < 10";
        System.out.println("Without Escaping, the content is:" + content);
        System.out.println("With Escaping, the content is:" + StringEscapeUtils.unescapeHtml4(content));
    }
}

Can you guess what the above program prints, It will print as below,

Without Escaping, the content is: 5 < 10
With Escaping, the content is: 5 < 10

So if we wan to unescape HTML tags, then we can leverage StringEscapeUtils.unescapeHtml4 method.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s