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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:10:00+00:00 2026-06-06T23:10:00+00:00

I wold like to save the given webservice url as xml file for offline

  • 0

I wold like to save the given webservice url as xml file for offline sax parsing.

In Online i am using SAX Parser to parse the given url .

URL sourceUrl = new URL("http://www.example.com/mobile/eventinfo.php?id=20);    
InputSource inputSource = new InputSource(sourceUrl.openStream());
inputSource.setEncoding("ISO-8859-1");

For that I am getting the inputsourse from url as above and now I want to save that inputsourse as .xml file for offline parsing.

Here User has to load the application for very first time in online. And inside the application we are providing offline facilities. If user sets the app to offline the inputsourse has to save the xml file in local memory.

If the user starts the application in offline the application has to parse the data from saved xml file.

If the user is starts the application online the data has to parse from the url.

Can any one help me out here or share the knowledge

I am generating the xml file like the following code

try {
    URL url = new URL(urlString);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setUseCaches(false);
    connection.connect();
    int responseCode = connection.getResponseCode();
    if(responseCode == 200){
        InputStream inputStream = connection.getInputStream();
        int size = connection.getContentLength();
        FileOutputStream fileOutputStream = new FileOutputStream(new File(getCacheDir(),filename));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String ch = null;
        while((ch = bufferedReader.readLine()) != null){
            fileOutputStream.write(ch.getBytes());
        }
    }else {

    }
}

but its raising an Exception as NetworkonMainThreadException at

  connection.connect();

thanks in advance.

  • 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-06T23:10:03+00:00Added an answer on June 6, 2026 at 11:10 pm

    I think for the first time you generate the file (contains ur xml) in sdcard,and every time check if that file exists in sdcard then parse same otherwise load data from url and generate xml file.

    Hope u get me what i say

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

Sidebar

Related Questions

I wold like to create this kind of URL for my users when they
I wold like to have in my model a CharField with fixed length. In
I'm using MySQL C API with C++ to connect to a database. I wold
I wold like to create a progressbar for my application, im running i got
I wold like to get the following variable name: class ClassA { public $my_name_is
I wold like to make a really small CMS based on codeigniter. And i
For me usable means that: it's being used in real-wold it has tools support.
before I begin with working with java an jUSB library I would like to
I am completely new to SSIS, in fact the below wold be my first
Basically I am trying to upload an image using ASIFormDataRequest. This is my following

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.