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

  • Home
  • SEARCH
  • 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 8544095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:28:15+00:00 2026-06-11T12:28:15+00:00

Possible Duplicate: Parsing an UTF-8 Encodded XML file I am parsing a UTF-8 Encoded

  • 0

Possible Duplicate:
Parsing an UTF-8 Encodded XML file

I am parsing a UTF-8 Encoded XML file which contains some arabic characters everything else is working properly except that the arabic characters are not displayed, some weird characters are displayed as below:

ÙØ±ÙÙ

here is the link to the XML “http://212.12.165.44:7201/UniNews121.xml” file am Parsing

below is the code

        public String getXmlFromUrl(String url) {

        try {
            return new AsyncTask<String, Void, String>() {
                @Override
                protected String doInBackground(String... params) {
                    //String xml = null;
                    try {

                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8");
                        HttpGet httpPost = new HttpGet(params[0]);
                        HttpResponse httpResponse = httpClient.execute(httpPost);
                        HttpEntity httpEntity = httpResponse.getEntity();
                        xml = new String(EntityUtils.toString(httpEntity).getBytes(),"UTF-8");

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                                    //just to remove the BOM Element    
                    xml=xml.substring(3);

            //Here am printing the xml and the arabic chars are malformed                                                       
                                    Log.i("DEMO", xml);
                    return xml;

                }
            }.execute(url).get();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return xml;
    }

Kindly note that no errors are occurring and everything is working properly just the arabic chars are malformed.

I would appreciate your help but please be specific in your answers

  • 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-06-11T12:28:16+00:00Added an answer on June 11, 2026 at 12:28 pm

    this

    xml = new String(EntityUtils.toString(httpEntity).getBytes(),"UTF-8");
    

    doesn’t do what you want. EntityUtils.toString() uses the default charset, then you call getBytes(), which uses platform encoding as well when no encoding is specified, then you call new String, which tries to read this byte[] as an UTF-8 string byte[].

    You simply need to call

    xml = EntityUtils.toString(httpEntity, "UTF-8");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Converting string into datetime I am parsing an XML file that gives
Possible Duplicate: Parsing XML in Cocoa iPhone - Can we parse .plist(xml) file using
Possible Duplicate: Parsing XML String in C# How to process the below XML file
Possible Duplicate: Parsing XML data to NSMutableArray iOS - iPhone <ForecastResult> <Forecast> <Date>2012-06-27T00:00:00</Date> <WeatherID>4</WeatherID>
Possible Duplicate: Parsing text in C Say I have written to a text file
Possible Duplicate: When is it OK to use an XML file to save information?
Possible Duplicate: Comparison of XML parsing APIs on the Java SE platform I am
Possible Duplicate: Parsing blank XML tags with LXML and Python Given the following XML
Possible Duplicate: Simplify PHP DOM XML parsing - how? Here is my XML (c.xml):
Possible Duplicate: Parsing CSV in java How to do I parse a csv file

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.