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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:08:33+00:00 2026-06-03T05:08:33+00:00

I have an XML file in the drawable-folder. I want parse the XML-file using

  • 0

I have an XML file in the drawable-folder. I want parse the XML-file using XML-parsing(sax parsing).
I used following code for that:

private void getDataFromFile(int mntFile) throws SAXException, IOException {
        // TODO Auto-generated method stub
        SAXParserFactory factory = SAXParserFactory.newInstance();
        System.out.println("in method");
        try {
            saxParser = factory.newSAXParser();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        DefaultHandler handler = new DefaultHandler() {

        boolean id = false;
        boolean name = false;
        boolean dep = false;


        public void startElement(String uri, String localName,String qName, 
                    Attributes attributes) throws SAXException {
            //System.out.println("in start");
            if (localName.equals("DOCTORID")) {
                id = true;
            }

            if (localName.equals("NAME")) {
                name = true;
            }

            if (localName.equals("DEAPRTMENT")) {
                dep = true;
            } 
        }

        public void endElement(String uri, String localName,
            String qName) throws SAXException { 
        }

        public void characters(char ch[], int start, int length) throws SAXException {

            if (id) {
                id = false;
            }

            if (name) {
                System.out.println("Name : " + new String(ch, start, length));
                mArryLstDoctorNames.add(new String(ch, start, length));
                Log.d("doctor","---"+mArryLstDoctorNames);
                name = false;
            }

            if (dep) {
                dep = false;
            }

        }

         };
           saxParser.parse(R.drawable.myxml, handler);
    }

But here saxParser.parse(R.drawable.myxml, handler); is showing compilation error.
It is the same code working for XML-files, which are on sdcard.

  • 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-03T05:08:34+00:00Added an answer on June 3, 2026 at 5:08 am

    You can’t store it to drawable folder, it is part of your package, store it elsewhere, yourpackage/data or SD card.
    R.drawble.xml is not use a input source.

    First you need to read the file, then pass it to a string, after that you can parse it.

    This is how:

    FileInputStream fis = openFileInput(yourfilepath);
            InputStreamReader isr = new InputStreamReader(fis);
            char[] inputBuffer = new char[reasonableLenght];
            // Fill the Buffer with data from the file
            isr.read(inputBuffer);
            String xml_data = new String(inputBuffer);
         //then you can do
    saxParser.parse(new InputSource(new StringReader(xml_data)), handler);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have student.xml file and am parsing this file using SAX Parser and now
I have an XML file which I need to parse using PHP and send
I have an image(320x210), I call the image from drawable folder in xml file...in
I have a file file1.png in my drawable folder. In main.xml I have an
In my \drawable-mdpi folder, I have an image named: test.jpg In my main.xml file,
I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I have an XML file (on the left) and I want to create multiple
I have an XML file format that contains a structure of questions: <question id=q101>
I have one ImageButton in my xml layout like that : <ImageButton android:id=@+id/tabsButton android:background=@drawable/button

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.