Escape html anchor tags with

How to escape each html dynamic anchor tag if URLs are different?

<a href="*_url">*_url</a>

I need the above code to be saved in the database as

&lt;a href="*_url"&gt;*_url&lt;/a&gt;

I've escaped other tags like <code>,<html>,<strong>... using

`StringUtils.replaceEach(post, search, replacement);` 

Because they are static tags. But the anchor tag holds "href" as dynamic content.

How can I get this done by a Javamethod at once.



Use StringEscapeUtils.escapeHtml() from Apache Commons Lang.

You can use on conjunction with your StringUtils.replaceEach. You may want to parse the anchor tag and encode the same using URLEncoder .

using an XML/HTML parser and getting the text within the two tags is easy.

i got it here

David Grant's solution seems correct to me. In the meantime escapeHtml has gotten obsolete. You can choose between escapeHtml3 and escapeHtml4.

1) Add to Your Gradle Dependency List:

compile 'org.apache.commons:commons-lang3:3.3.2'

For Maven it is:



import org.apache.commons.lang3.StringEscapeUtils;

3) Then invoke...


Need Your Help

Cancelling a BackgroundWorker

c# .net-4.5 backgroundworker

My DoWork for backgroundworker1 sets a wait timer via a class WakeUp, it works well.

Extract continous siblings in XSL

html xslt siblings

I have an HTML file like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.