1

I have an URL like this:

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

here I want to decode < and > 


Prashant Aggarwal
  • 188
  • 1
  • 5
  • 20

4 Answers4

2

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

String string= StringEscapeUtils.unescapeHtml(encodedString);
Subhrajyoti Majumder
  • 39,719
  • 12
  • 74
  • 101
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
  • 45,376
  • 16
  • 70
  • 78
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
  • 10,440
  • 8
  • 47
  • 64
1

Use methods provided by Apache Commons Lang

import org.apache.commons.lang.StringEscapeUtils;
// ...
String afterDecoding = StringEscapeUtils.unescapeHtml(beforeDecoding);
Suresh Atta
  • 118,038
  • 37
  • 189
  • 297
Melih Altıntaş
  • 2,455
  • 18
  • 35