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 8258923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:42:47+00:00 2026-06-08T02:42:47+00:00

Welcome all I’m developing a Java app, that calls a PHP from internet that

  • 0

Welcome all

I’m developing a Java app, that calls a PHP from internet that it’s giving me a XML response.

In the response is contained this word: “Próximo”, but when i parse the nodes of the XML and obtain the response into a String variable, I’m receiving the word like this: “Pr& oacute;ximo”.

I’m sure that the problem is that i’m using different encoding in the Java app then encoding of PHP script. Then, i supose i must set encoding to the same as in your PHP xml, UTF-8

This is the code i’m using to geat the XML file from the PHP.

¿What should i change in this code to set the encoding to UTF-8? (note that im not using bufered reader, i’m using input stream)

        InputStream in = null;
        String url = "http://www.myurl.com"
        try {                              
            URL formattedUrl = new URL(url); 
            URLConnection connection = formattedUrl.openConnection();   
            HttpURLConnection httpConnection = (HttpURLConnection) connection;
            httpConnection.setAllowUserInteraction(false);
            httpConnection.setInstanceFollowRedirects(true);
            httpConnection.setRequestMethod("GET");
            httpConnection.connect();               
            if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK)
                in = httpConnection.getInputStream();   

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();                     
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(in);
            doc.getDocumentElement().normalize();             
            NodeList myNodes = doc.getElementsByTagName("myNode"); 
  • 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-08T02:42:49+00:00Added an answer on June 8, 2026 at 2:42 am

    When you get your InputStream read byte[]s from it. When you create your Strings, pass in the CharSetfor “UTF-8”. Example:

    byte[] buffer = new byte[contentLength];
    int bytesRead = inputStream.read(buffer);
    String page = new String(buffer, 0, bytesRead, "UTF-8");
    

    Note, you’re probably going to want to make your buffer some sane size (like 1024), and continuously called inputStream.read(buffer).


    @Amir Pashazadeh

    Yes, you can also use an InputStreamReader, and try changing the parse() line to:

    Document doc = db.parse(new InputSource(new InputStreamReader(in, "UTF-8")));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use Facebook ID to welcome all facebook user that enter my
Welcome all It is possible to use SimpleXML for android in commercial apps? THis
just in pure gdi. thoughts or code are all welcome.
Goodmorning lads, First of all - R.I.P TPB! Welcome malaysiabay.org for the Dutchies <3
Lets say I have a WelcomeActivity. All it does is show you a welcome
Welcome! I have a recursive public static method named less that takes a tree
Welcome, I notice that Youtube make some changes into their website code. Anyone have
I have this welcome.php which the administrator is redirected when he is authenticated, i
How to display Welcome %username% in all the webpages, is there any possibly to
My app is simple : A controller :main with 3 actions : welcome,form_receiver and

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.