Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5937989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:37:13+00:00 2026-05-22T15:37:13+00:00

I’ve to HTML unescape a String (HTML escaped XML File (So all val in

  • 0

I’ve to HTML unescape a String (HTML escaped XML File (So all val in my String are & lt;TAG& gt;val& lt;/TAG& gt; and so on) Size ~1,4MB so that I can use the unescaped XML in a parser)

The problem I’m running into is that I always get an out of memory exception when I try to get the unescaped String when I’m using StringEscapeUtils.unescapeHtml(String) (apache-commons-lang-2.6 library).

I also tried the method of the basic android api to unescape the string but beside the fact that it was slow as hell the out of memory exception even occured with smaller Strings (~700kb).

Can someone suggest me how I can handle such a String tranformation without running into an out of memory exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:37:14+00:00Added an answer on May 22, 2026 at 3:37 pm

    Java has some good core facilities to get do this really simple.
    The solution below uses regular expression to go through your content and allows you to replace the characters. This solution does require to do a little work in that you need to provide the escape codes. You can find a list of escape codes here [http://www.w3.org/TR/html4/sgml/entities.html][1] or Google the web for others.

    Here is the code below:

    import java.util.regex.*;
    import java.util.*;
    
    public class HtmlUnescape {
        public static void main(String[] args){
            HashMap<String,String> codes = new HashMap<String,String>();
            codes.put("&lt;", "<");
            codes.put("&gt;", ">");
            codes.put("&#34;", "\"");
    
            String html = "&lt;html&gt;&lt;head&gt;&lt;title&gt;Hello&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;The great escape &#34;example&#34;&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;";
    
            Matcher matcher = Pattern.compile("&#*\\w\\w\\w?\\w?;").matcher(html);
            StringBuffer matchBuffer = new StringBuffer();
            while(matcher.find()){
                matcher.appendReplacement(matchBuffer, codes.get(matcher.group()));
            }
            matcher.appendTail(matchBuffer);
            System.out.println (matchBuffer.toString());
        }
    }
    

    What is going on in the code:

    • First, the hash stores the codes to unescape.
    • Second, variable html stores escape HTML to process.
    • Next, we use the regex expression to search and replace the escaped codes using:
      • Matcher.find(),
      • Matcher.appendReplacement(), and
      • Matcher.appendTail() methods.

    Try that. I have no insight on performance of large files such as yours. But, the code is simple enough to where you can tweak it to get the desired performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.