java - How to parse three xml files in Android Application -
i did parsing single xml file , displayed values in textview
. tried 3 xml files couldn't find exact way parse 3 xml files, i'm not able find problem.
the code provided below. can 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 = getassets().open("file.xml"); saxparser.parse(is, handler); } catch (exception e) { e.printstacktrace(); }
Comments
Post a Comment