Android XMLPullParser TutorialAndroid recommends to use XMLPullParser to parse the xml file than SAX and DOM because it is fast. The org.xmlpull.v1.XmlPullParser interface provides the functionality to parse the XML document using XMLPullParser. Events of XmlPullParserThe next() method of XMLPullParser moves the cursor pointer to the next event. Generally, we use four constants (works as the event) defined in the XMLPullParser interface. START_TAG :An XML start tag was read. TEXT :Text content was read; the text content can be retrieved using the getText() method. END_TAG : An end tag was read. END_DOCUMENT :No more events are available Example of android XMLPullParseractivity_main.xmlDrag the one listview from the pallete. Now the activity_main.xml file will look like this: File: activity_main.xml xml documentCreate an xml file named employees.xml inside the assets directory of your project. File: employees.xml Employee classNow create the Employee class that corresponds to the xml file. File: Employee.java XMLPullParserHandler classNow write the code to parse the xml file using XMLPullParser. Here, we are returning all the employee in list. File: XMLPullParserHandler.java MainActivity classNow, write the code to display the list data in the ListView. File: MainActivity.java Output:Next TopicAndroid Json Parsing Tutorial |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India