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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:55:29+00:00 2026-06-05T16:55:29+00:00

I am trying to pass a .xml file from my res folder to an

  • 0

I am trying to pass a .xml file from my res folder to an XMLReader in order to parse it to an object:

private void parseXML() {
    String parsedData = "";
       try {
           Log.w("AndroidParseXMLActivity", "Start");
           /** Handling XML */
           SAXParserFactory spf = SAXParserFactory.newInstance();
           SAXParser sp = spf.newSAXParser();
           XMLReader xr = sp.getXMLReader();

           QuestionXMLHandler myXMLHandler = new QuestionXMLHandler();
           xr.setContentHandler(myXMLHandler);
           InputSource inStream = new InputSource();
           Log.w("AndroidParseXMLActivity", "Parse1");

           inStream.setCharacterStream(new StringReader(getResources().getXml(R.xml.questions).toString()));
           Log.w("AndroidParseXMLActivity", "Parse2");

           xr.parse(inStream);
           Log.w("AndroidParseXMLActivity", "Parse3");

           ArrayList<QuestionMaster> questionList = myXMLHandler.getQuestionsList();
           for(int i=0;i<questionList.size();i++){
                QuestionMaster question = questionList.get(i);
                parsedData = parsedData + "----->\n";
                parsedData = parsedData + "Queston No: " + question.getQuestionNo() + "\n";
                parsedData = parsedData + "QuestionText: " + question.getQuestionText() + "\n";
                parsedData = parsedData + "CorrectAnswer: " + question.getQuestionText() + "\n";
                parsedData = parsedData + "WrongAnswer1: " + question.getQuestionText() + "\n";
                parsedData = parsedData + "WrongAnswer2: " + question.getQuestionText() + "\n";
                parsedData = parsedData + "WrongAnswer3: " + question.getQuestionText() + "\n";
                parsedData = parsedData + "Answered: " + question.isAnswered() + "\n";
                parsedData = parsedData + "QuestionText: " + question.isAnsweredCorrectly() + "\n";
            }
            Log.w("AndroidParseXMLActivity", "Done");
        }catch (Exception e) {
            Log.w("AndroidParseXMLActivity",e );
        }
        xmlOutput.setText(parsedData);
    }
}

I am sure that it is the line:

inStream.setCharacterStream(new StringReader(getResources().getXml(R.xml.questions).toString()));

Could someone guide me to pass this .xml file to the XMLReader.

edit:

Changed it to:

InputSource inStream = new InputSource(getResources().openRawResource(R.raw.questions));
  • 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-05T16:55:32+00:00Added an answer on June 5, 2026 at 4:55 pm
    InputStream inStream = getResources().openRawResource(R.raw.questions);
    xr.parse(inStream);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass items from a mysql database into an xml file
I'm trying to parse an xml file output from googletest to display the results
I am trying to pass variables from an xml file to the father class
I'm trying to parse an xml file using lxml. xml.etree allowed me to simply
I'm trying to create an XML string and pass it to another method where
I'm trying to extract data from an xml file. A sample of my code
I'm trying to use simplexml to load an xml file from a server: $xml
I'm trying to access an XML file within a jar file, from a separate
I am trying to pass data from the database in XML format to an
I am having a problem in trying to pass a ArrayList Object from Activity

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.