Introduction
In this article, you will learn about XML parsing with the pull parser
XML Parsing
XML parsing is a process of converting data from a server in a machine-readable form.
XML pull parser
The XML pull parser is an interface that defines the parsing functionality. It provides two key methods next() that provide access to high-level parsing events. The current event state of the parser can be determined by the geteventType() method. Initially, the parser lies in the START_DOCUMENT state.
The following are the events seen by next():
-
START_TAG:
an XML start tag was read.
-
Text:
Text content was read. The text content was retrieved using the getText() method.
-
END_TAG:
A tag was read.
-
END_DOCUMENT:
No more events are available.
Step 1
Create an XML file and write this:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- tools:context=".MainActivity">
- <ListView
-
- android:id="@android:id/list"
-
- android:layout_width="fill_parent"
-
- android:layout_height="wrap_content"/>
-
- </RelativeLayout>