Android XMLPullParser Tutorial
Android 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 XmlPullParser
The 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 XMLPullParser
Drag the one listview from the pallete. Now the activity_main.xml file will look like this:
Create an xml file named employees.xml inside the assets directory of your project.
Now create the Employee class that corresponds to the xml file.
Now write the code to parse the xml file using XMLPullParser. Here, we are returning all the employee in list.
Now, write the code to display the list data in the ListView.
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week