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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:10:21+00:00 2026-06-11T13:10:21+00:00

I want to parse a XML file from a server on internet and save

  • 0

I want to parse a XML file from a server on internet and save it locally for some time so that if the connectivity is lost I can still see the information on app.

I am able to successfully parse the XML file from the internet. I am also able to save it in the cache directorygetCacheDir(), files directorygetFilesDir() and external storage.

Now, I want to parse the local XML file and still want to use the same function that I used to parse the XML from internet. However after several tries and hours of searching I am not able to parse the inputstream from the file stored in Cache directory or the Files directory. The only directory the function works on is the external directory.

So this code WORKS:

inputstream is;
File file = new File ("/mnt/sdcard/Fmobile/Cache","Newfile.xml");                   
is = new BufferedInputStream(new FileInputStream(file));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
Document dom = db.parse(is); 

While the following code does NOT work.

inputstream is;
File file = new File (getFilesDir(),"Newfile.xml");                 
is = new BufferedInputStream(new FileInputStream(file));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
Document dom = db.parse(is); **// Error is given on this line : "Is a directory"**

Can anyone tell me what is the difference between the above two code or what should be done to get the inputstream from the Cache directory or the Files directory.
Just so you know I have tried replacing the getFilesDir() with the path to the file.

Most solutions I have searched for talk about storing the file in asset or res folder but I cannot do that because it is a dynamic file which will keep changing and that’s why I need to use cache and timeout.

I am sorry for any mistakes that I might have made while posting this. This is my first post.

The Log Cat is as follows:

04-04 11:27:24.579: I/com.example.app1.FMobileActivity(16029): Running Form [2] Local File
04-04 11:27:24.579: I/com.example.app1.FMobileActivity(16029): ProcessForm Data2
04-04 11:27:24.579: I/com.example.app1.FMobileActivity(16029): /data/data/com.example.app1/cache/Newfile2.xml
04-04 11:27:24.589: E/com.example.app1.FMobileActivity(16029): Error occurred in ProcessForm:Is a directory
04-04 11:27:24.589: W/System.err(16029): java.io.IOException: Is a directory
04-04 11:27:24.599: W/System.err(16029):    at org.apache.harmony.luni.platform.OSFileSystem.read(Native Method)
04-04 11:27:24.599: W/System.err(16029):    at dalvik.system.BlockGuard$WrappedFileSystem.read(BlockGuard.java:165)
04-04 11:27:24.599: W/System.err(16029):    at java.io.FileInputStream.read(FileInputStream.java:290)
04-04 11:27:24.599: W/System.err(16029):    at java.io.FileInputStream.read(FileInputStream.java:245)
04-04 11:27:24.609: W/System.err(16029):    at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:140)
04-04 11:27:24.609: W/System.err(16029):    at java.io.BufferedInputStream.read(BufferedInputStream.java:225)
04-04 11:27:24.609: W/System.err(16029):    at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1044)
04-04 11:27:24.609: W/System.err(16029):    at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:114)
04-04 11:27:24.609: W/System.err(16029):    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:107)
04-04 11:27:24.609: W/System.err(16029):    at com.example.app1.FMobileActivity.GetFormData(FMobileActivity.java:315)
04-04 11:27:24.609: W/System.err(16029):    at com.example.app1.FMobileActivity.onCreate(FMobileActivity.java:58)
04-04 11:27:24.609: W/System.err(16029):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-04 11:27:24.609: W/System.err(16029):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666)
04-04 11:27:24.609: W/System.err(16029):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1727)
04-04 11:27:24.609: W/System.err(16029):    at android.app.ActivityThread.access$1500(ActivityThread.java:124)
04-04 11:27:24.609: W/System.err(16029):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:974)
04-04 11:27:24.609: W/System.err(16029):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 11:27:24.609: W/System.err(16029):    at android.os.Looper.loop(Looper.java:130)
04-04 11:27:24.609: W/System.err(16029):    at android.app.ActivityThread.main(ActivityThread.java:3859)
04-04 11:27:24.609: W/System.err(16029):    at java.lang.reflect.Method.invokeNative(Native Method)
04-04 11:27:24.609: W/System.err(16029):    at java.lang.reflect.Method.invoke(Method.java:507)
04-04 11:27:24.609: W/System.err(16029):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
04-04 11:27:24.609: W/System.err(16029):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:647)
04-04 11:27:24.609: W/System.err(16029):    at dalvik.system.NativeStart.main(Native Method)
04-04 11:27:24.609: E/com.example.app1.FMobileActivity(16029): Couldn't parse the Form.
04-04 11:27:24.689: D/dalvikvm(16029): GC_EXTERNAL_ALLOC freed 118K, 48% free 2837K/5379K, external 2743K/2773K, paused 33ms
  • 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-11T13:10:22+00:00Added an answer on June 11, 2026 at 1:10 pm

    I ended up using the following to get a document from a string. String can be obtained by downloading a file or by reading a file locally. SO it solves the problem I had. If anyone needs help in getting the contents of local file as a string let me know in comments. It is fairly simple same fro fetching data from online server.

    public final static Document XMLfromString(String xml)
    {
        if(xml!=null)
        {
        /* Replace the & in string with &amp (if any) */
            String xmlNew=clearRefs(xml);
            Document doc = null;
        //  Log.v(tag,"After Clearing refs::"+xmlNew);
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            Log.v(tag,"Trying Obtaining Document");
            try {
                DocumentBuilder db = dbf.newDocumentBuilder();
                InputSource is = new InputSource();
                is.setCharacterStream(new StringReader(xmlNew));
                doc = db.parse(is); 
            } catch (ParserConfigurationException e) {
                Log.e(tag,"XML parse error: " + e.getMessage());
                return null;
            } catch (SAXException e) {
                connectionStatus="No data received";
                e.printStackTrace();
                return null;
            } catch (IOException e) {
                Log.e(tag,"I/O exeption: " + e.getMessage());
                connectionStatus="No data received";
                return null;
            }
            return doc;
        }
        else
        {
            connectionStatus="Null string Passed";
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to copy the xml file from server to save it to locally,
I want to parse some XML-file in Qt, but that file is located at
I want to parse xml file in utf-8 and sort it by some field.
I have a magazine application i want that it load file from server and
hi guys,i parse my file xml from my server NSString *theXML = [[NSString alloc]
I want to parse an XML file from URL using JDOM. But when trying
I want to parse the xml file with dynamic content using DOM parser in
I want to parse a xml file using xquery in Ruby, I found this
I want to parse a large XML file and I have two options: Perl
I have an XML file and parse it into my PHP document. I want

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.