Android Tutorial – How to Use XML Parser Android with Simple Example for Beginner

Seegatesite – I’ll share how to create xml parser android to retrieve xml data from a website. Continuing my articles about programming android, android xml parser used in order to communicate with a webservice that displays data in xml format. Android developer on the site, the use of XML parser is very easy to understand, I will discuss how to use xml parser in android with more simple examples to make it more easily understood by beginners.

There are various XML parsers we can use on the Android platform. For XML, Android recommends the use of the XMLPullParser.

We recommend XmlPullParser , which is an efficient and maintainable way to parse XML on Android.

As a beginner, I use the library XMLPullParser for ease of use.

Tutorial how to use of XML Parser android with XMLPullParser step by step

1. Make a simple xml file on your PHP server as rss.xml and place it in the folder “android” as shown below (If using xampp, the htdocs folder -> Android -> rss.xml)

How To Create Xml Parser Android With Xmlpullparser Step By Step

Then copy these script on your rss.xml

Please check your browser does xml has been loaded properly.

How To Create Xml Parser Android Android Tutorial

The next step we will begin to make the main parts android app

1. Create an android project in advance, if you don’t know how to create android project on android studio, please read the introduction android for beginner. In this example I gave the name BelajarXmlParser

2. Create a java class as then copy the following script

A brief description :

Which need to be understood to xml parser as a beginner android programmer is two following sript

I. Looping the parent TAG

While Xml Parser To Get Xml Text How To Use Xml Parser Android For Beginner

If the parent’s TAG has child tags, we should use a while loop to retrieve the text on the tag inside.

II. Taking Text in a TAG

Get Text From Tag Xml How To Use Xml Parser Android

To get the text in the tag starts with parser.require (XmlPullParser.START_TAG, ns, “title”); and ends with parser.require (XmlPullParser.END_TAG, ns, “title”); .

Please read more detail on

– To get the text value required the following method

Gettext Xml Parser How To Use Xml Parser Android For Begginer

3. Open your activity_main.xml and copy the following script

Remember to replace com.example.sigit.belajarxmlparser with the name of your package. We create WebView element to display results from xml parser.

4. Add the following script on string.xml the folder res -> values -> strings.xml

Add New Value On Strings Xml How To Use Xml Parser Android Developer

5. Add scripts on (main script)

Explanation :

I use AsyncTask class to execute xml parser script ( that we created before. For a full explanation of AsyncTask class I will discuss in another opportunity.

Using Asynctask For Execute Xml Parser Script How To Use Xml Parser Android Step By Step

When AsyncTask in execution, it’s will run the two procedures doInBackground and onPostExecute

– doInBackground call the loadXmlFromNetwork’s method

Execute Xml Parser From Main Activity Android How To Use Xml Parser Android For Beginner
Taking xml via the address “” with the DownloadUrl method , then parser the xml file with RssXmlParser class that we created before into array list (entries = feedXmlParser.parse (stream );)

To sort through the array list above using the following functions

– onPostExecute will display the xml parser results into a WebView’s layout that we created earlier on activity_main.xml

When the application is executed the results are as shown below

How To Use Xml Parser Android For Begginer Step By Step

Don’t forget to add the following script on AndroidManifest.xml

Download example how to use XMLFullParser  in the link below

Read another tutorial android here

Thus article about Android Tutorial – How to Use XML Parser Android with Simple Example for Beginner, hope useful 🙂


The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.


 Add your comment
  1. this shortlink has been disabled. It was found to be violating our Terms of Service. Click here and here for more information about our terms and policies respectively.

    so? where can I download? Thx?!

  2. It doesn’t work: IOExeption, “Unable to load content. Check your network connection.”

  3. Hello Sigit,

    many thanks for this great tutorial. You helped me a lot to undestand how to parse xml. 🙂

    There are still some points unclear. May I ask you some questions about it please? 🙂

    The script which you parse has html tags like title or url. Is it also possible to parse a xml-script which looks like this:

    Harry Potter
    J. K. Rowling

    The Hunger Games
    Suzanne Collins

    Asterix and Obelix
    René Goscinny

    Do I have to parse this to Html, too?

    Thank you in Advance.

    Maria – a complete beginner 😉

  4. Ok, last try. 🙂 I left out the following sign:
    “name>Harry Potter
    “author>J. K. Rowling

  5. 🙂 Now it worked. More or less. 🙂

    I am sorry for making such strange comments.

    Have a nice day and thank you. 🙂

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

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