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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:13:14+00:00 2026-05-19T01:13:14+00:00

hai every one. i am new to android. in my project i had some

  • 0

hai every one. i am new to android. in my project i had some problems reading xml files. In my xml i have included some audios and videos paths and i want to read the xml file through the code and i want to display some images n my view if there are some audio or video files. can any body tel how to read the xml file.
thanking you 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-05-19T01:13:15+00:00Added an answer on May 19, 2026 at 1:13 am

    Ok first you need to create a parser Below is the code to do this:

    public static void readTemplateFile(Context context) {

        /**
         Include File Checking
         */
    
        try {
            XML_Handler_Template myExHan = new XML_Handler_Template();
    
            InputStreamReader isr =  new
            FileReader( new File(Environment.getExternalStorageDirectory().getPath() + "/Library Template.xml" ));
    
            XML_Handler_Template.context = context;
    
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
    
            XMLReader xr = sp.getXMLReader();
    
            xr.setContentHandler((ContentHandler) myExHan);
    
            xr.parse(new InputSource(isr));
    
    
        } catch (Exception e) {
    
            Toast.makeText(context, ">" + e.getMessage(), Toast.LENGTH_LONG).show();
    
    
        }
    
    }
    

    You then need a Handler Class. In the above example my class is called XML_Handler_Template.

    FileReader( new File(Environment.getExternalStorageDirectory().getPath() + “/FILEPATH/FILE.XML” ));

    Here is the XML_Handler_Class at the moment it is blank:

    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;

    public class XML_Handler_Template extends DefaultHandler{

        public static Context context = null;
    
    @Override
    public void startDocument() throws SAXException {
        //this is called when the document is first read
    }
    
    @Override
    public void startElement(String namespaceURI, String localName,
            String qName, Attributes atts) throws SAXException {
                        //This is called when a new Tag is opened
                        //localName holds the Tag Name, the Value is got from the 
                        //Characters function at the end of this class
    
                       //the attributes for each tag are stored in the atts array, you can either handle the attribute values here or pass the information to a separate function to handle them,
                       if (atts.getLength()>0){
                for (int i=0;i<atts.getLength();i++){
    
                    addAttrib(atts.getLocalName(i) , atts.getValue(i))  ;
    
                }
            }
    }
    
    @Override
    public void endElement(String namespaceURI, String localName, String qName)
    throws SAXException {
        //This is called when a Tag is closed
    }
    
    @Override
    public void endDocument() throws SAXException {
                    //this is called when the document is closed
    }
    
    @Override
    public void characters(char ch[], int start, int length) {
                //This is where the value of a Tag are read
        String value = new String( ch , start , length );
                // You may want to include a replaceAll("\r","") and replaceAll("\n","") to remove any hidden chars
    
    }    
    

    }

    have a play with this and see how you get on for now =0) I passed a context to the class so whilst i was learning I could use toasts to show me the values that were being read.

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

Sidebar

Related Questions

No related questions found

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.