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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:15:29+00:00 2026-06-15T21:15:29+00:00

I need sometimes read XML file from remote server, and replace data in XML

  • 0

I need sometimes read XML file from remote server, and replace data in XML on my Android device.
I read data through XmlPullParser:

XmlPullParser users;
            try {
                URL xmlUrl = new URL("http://xx.xx.xx.xx/1.xml");
                users = XmlPullParserFactory.newInstance().newPullParser();
                users.setInput(xmlUrl.openStream(), null);

            }

How can I replace it on Android?

  • 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-15T21:15:29+00:00Added an answer on June 15, 2026 at 9:15 pm

    Simply use this code, it’s overwrites the file with the new file you download from the internet.

    public static boolean downloadFile(String fileToDownload, File newPath,
                String newFileName) {
            try {
                URL url = new URL(fileToDownload);
                HttpURLConnection urlConnection = (HttpURLConnection) url
                        .openConnection();
                urlConnection.setRequestMethod("GET");
                urlConnection.setDoOutput(true);
                urlConnection.connect();
                if (!newPath.isDirectory()) {
    
                    CreateLog.createFolder(newPath.toString());
                }
                File file = new File(newPath.toString() + "/" + newFileName);
                if (!file.isFile()) {
                    CreateLog.writeLogToFile(newPath.toString() + newFileName,
                            "%TEMP%");
                }
    
                FileOutputStream fileOutput = new FileOutputStream(file);
                InputStream inputStream = urlConnection.getInputStream();
    
                byte[] buffer = new byte[1024];
                int bufferLength = 0;
    
                while ((bufferLength = inputStream.read(buffer)) > 0) {
                    fileOutput.write(buffer, 0, bufferLength);
                }
                fileOutput.close();
                return true;
    
            } catch (MalformedURLException e) {
                CreateLog.addToLog(e.toString());
                return false;
            } catch (IOException e) {
                CreateLog.addToLog(e.toString());
                return false;
            }
        }
    
    public static void createFolder(String filePath) {
        File createFolder = new File(filePath);
        createFolder.mkdirs();
    }
    

    A cleaner method is to use a Asynctask, the code runs in a new thread. But it’s a bit harder to code.

    private class GetProblems extends AsyncTask<String, Integer, String> {
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
            }
    
            @Override
            protected String doInBackground(String... params) {
                for (String myUrl : params) {
    
                    try {
    
                        URL url = new URL(myUrl);
                        URLConnection ucon = url.openConnection();
                        ucon.setRequestProperty("Accept", "application/xml");
    
                        InputStream is = ucon.getInputStream();
                        BufferedInputStream bis = new BufferedInputStream(is);
    
                        ByteArrayBuffer baf = new ByteArrayBuffer(50);
                        int current = 0;
                        while ((current = bis.read()) != -1) {
                            baf.append((byte) current);
                        }
                        String str = new String(baf.toByteArray(), "UTF8");
    
                        return str;
    
                    } catch (MalformedURLException e) {
                        CreateLog.addToLog("[GetProblems] " + e.toString());
                    } catch (IOException e) {
                        CreateLog.addToLog("[GetProblems] " + e.toString());
                    }
                }
                return "error";
            }
    
            @Override
            protected void onProgressUpdate(Integer... values) {
                super.onProgressUpdate(values);
                // updateProgressBar(values[0]);
            }
    
            @Override
            protected void onPostExecute(String result) {
                super.onPostExecute(result);
    
                            ...write result to a file
    
            }
        }
    

    Run the AsyncTask code:

    new GetProblems().execute("http://myurl.com/xmlfile.xml");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SqlDataReader to read data from SQL Server. However sometimes I want
I have an application where i sometimes need to read from file being written
For my application, I need to serialize data to file using XML, so I
I need to open an manifest.v3 file and read the version field (xml file),
I have a complex structure xml from which I need to read some element
I read a data from a text file using TextReader TextReader reader = new
I'am programing in C language. Sometimes we have to read large data from files
I sometimes need to run gacutil.exe or installutil.exe, etc. from the command line. Is
In my app I sometimes need to rebuild and repopulate database file. SQLite databse
Sometimes you need to create a very simple single file application in Qt4. However

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.