1

I have an URL like this:

localhost:8080/demo?xml=hello"<xyz>&#xa";

here I want to decode < and > 


Prashant Aggarwal
  • 208
  • 1
  • 7
  • 20

4 Answers4

2

From apache Common -StringEscapeUtils#escapeHtml() can simplify your job.

String string= StringEscapeUtils.unescapeHtml(encodedString);
Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103
1

First extract the part you want to decode:

 String str = url.substring(str.indexOf('"') + 1, str.lastIndexOf('"'));

Then decode it using StringEscapeUtils.unescapeHtml4:

 String result = StringEscapeUtils.unescapeHtml4(str);
micha
  • 47,774
  • 16
  • 73
  • 80
1

I assume you are able to extract the String between quotes in the URL. Then you could use Apache Commons Lang (StringEscapeUtils.unescapeHtml4) to unescape special entities:

String unescapedString = StringEscapeUtils.unescapeHtml4("<xyz>&#xa");
LaurentG
  • 11,128
  • 9
  • 51
  • 66
1

Use methods provided by Apache Commons Lang

import org.apache.commons.lang.StringEscapeUtils;
// ...
String afterDecoding = StringEscapeUtils.unescapeHtml(beforeDecoding);
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
Melih Altıntaş
  • 2,495
  • 1
  • 22
  • 35