How to parse three xml files in Android Application

I did the parsing for single xml file and i displayed the values in textview. I tried with 3 xml files but i couldn’t find the exact way to parse 3 xml files, am not able to find my problem. I have given my code below. Can anyone give suggestions.

tv = (TextView) findViewById(R.id.textView4);
tv1 = (TextView) findViewById(R.id.textView5);

try {
    SAXParserFactory factory = SAXParserFactory.newInstance();

    SAXParser saxParser = factory.newSAXParser();


    DefaultHandler handler = new DefaultHandler() {

        boolean name = false;

        boolean salary = false;


        public void startElement(String uri, String localName, String qName,
                                 Attributes attributes) throws SAXException {
            if (qName.equalsIgnoreCase("name")) {
                name = true;
            }
            if (qName.equalsIgnoreCase("salary")) {
                salary = true;
            }
        }//end of startElement method  

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

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

                tv.setText(tv.getText() + "n" + new String(ch, start, length));
                name = false;
            }
            if (salary) {
                tv1.setText(tv1.getText() + "n" + new String(ch, start, length));
                salary = false;
            }
        }//end of characters  

    };//end of DefaultHandler object  

    InputStream is = getAssets().open("file.xml");
    saxParser.parse(is, handler);

} catch (Exception e) {
    e.printStackTrace();
}


Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.