Android: Reading, using and working with XML data and web services in Android

Posted July 19th @ 8:37 pm by Boyan Tsolov


One of the most powerful aspects of any mobile application for a 3G phone is that it can connect to the Internet. By connecting to the Internet the application can offer much more value to the user since it becomes an interface for a web-based component, e.g. using Twitter’s API to create a Twitter application so that you can get your Twitter updates without having to open the mobile browser. The most common way of interfacing with a web-based component is by using web services in XML format.

While trying to developer my own app which reads a web service from my own server, I ran into a lot of difficulties in implementing the client that consumes the web service. Android does not have libraries for XPath handling of XML documents, so it makes deciphering XML data a little bit more difficult. From what I’ve read online the Android team is currently working on including such libraries in future versions.

After some digging around I found an amazing link that shows different methods for consuming an XML file in Android and parsing through it without the use of XPaths. The link is this: Working with XML on Android. To start off, this link is an absolute must-read. Everything that I am going to write in my post here relates to this link. The code offered on that webpage uses polymorphism to show you 4 different methods of working with XML data. It provides a fully-functional Android application and all the source code for it. The source code can be found here:

My post today will concentrate on how to customize the code from the application in the above link, in order to read and parse your own XML data. If you are a Java pro, you might not need this post. My Java is a little rusty, so I needed some time to figure out exactly what I had to change and where in order to get this to work with my own web service XML. Now that I’ve figured it out, I thought I’d share it. In my next post I will give the simplified version of this code – where there is no polymorphism, and thus there are only the minimum number of classes needed to implement this XML-reading solution. I can’t offer this simplified code right now – because I haven’t coded it yet :).

So until I post the simplified source code for working with XML data in Android, here are some tips on getting through the larger polymorphism-based source code and customizing it for your own XML data:

1. First off, read over the link Working with XML on Android as much as you can.

2. Download the source code for the Android application that they offer:

3. Import the project into your Eclipse workspace by right-clicking in Project Explorer and selecting “Import”.

01 Import

4. Select “Existing Projects into Workspace”

5. Browse to the directory where you extracted the ZIP file with the source code and then click on the Next buttons to finish off the wizard. The project is called “AndroidXml”.

6. You will now see the project in your workspace:

02 project

7. Here is a quick breakdown of what some of those Java classes do:

- is the main activity that gets started. It lists the items from the XML data using a ListActivity. In this project the items come from an RSS feed.

-,,, RSSHandler.hava are all classes that this particular example uses to set the framework for polymorphism.

- This example uses 4 methods for grabbing the XML data and reading it.The 4 methods that this example uses are:

1. (the default)




These 4 classes all extend

8. In order to customize this for your own XML file you need to edit the following places (assuming you are using AndroidSaxFeedParser, which is the default):

- you need to change the URL location of the web service or XML document in the global variable here:

static String feedUrl = "";

- you need to change the root node of your XML document. This is stored in the String called RSS.

static final String RSS = "RootNode";

- you need to change this class according to the nodes that your XML document has.

The nodes CHANNEL and ITEM refer to the nodes <Channel> and <Item> in the RSS feed that this example uses. You need to change them to mimic your nodes from your XML document:

static final String CHANNEL = "channel";
static final  String ITEM = "item";

The other constants that are declared refer to the nodes for each repeating item.

static final  String PUB_DATE = "pubDate";
static final  String DESCRIPTION = "description";
static final  String LINK = "link";
static final  String TITLE = "title";

For this particular example, since an RSS feed XML document is used, it has repeating nodes for <Description>, <Link>, <Title>, <PubDate>. You need to change this structure to mimic your structure.

Note: Remember that if you change the name of the constants (as opposed to the value of the constants), you will need to change other classes which call these constants.

- If you change the names of the constants, you will have to update in this section:

        item.getChild(TITLE).setEndTextElementListener(new EndTextElementListener(){
            public void end(String body) {
        item.getChild(LINK).setEndTextElementListener(new EndTextElementListener(){
            public void end(String body) {
        item.getChild(DESCRIPTION).setEndTextElementListener(new EndTextElementListener(){
            public void end(String body) {
        item.getChild(PUB_DATE).setEndTextElementListener(new EndTextElementListener(){
            public void end(String body) {

As you can see this section is hardcoded for the 4 nodes that are expected in this XML document (TITLE, LINK, DESCRIPTION, PUB_DATE). You will need to change this section and hardcode this for your own nodes.

- If you change the names of the higher-level nodes, i.e. <Channel> and <Item>, then you need to update the following section of

Element itemlist = root.getChild(CHANNEL);
Element item = itemlist.getChild(ITEM);

And that is all. The customized code will use the AndroidSaxParser implementation of an XML Parser, it will go to the URL you provided in, and it will iterate through the updated nodes as you have labeled them in and

In my next post I will provide a simplified version of this code, which does not use polymorphism. It will (hopefully) use the minimum required classes to get XML data and parse it.

4 Trackbacks/Pingbacks

  1. Pingback: Android: Simplified source code for parsing and working with XML data and web services in Android | Warrior Point - Latest News & Tutorials on SaaS, Android and On-demand Software on July 20, 2009
  2. Pingback: Anybody Help me ! I got some Problem running android application using ANDROID_SAX - Android Forums on March 12, 2010
  3. Pingback: My first learning log for developing android apps « Michelle Melkman Broadcast blog on January 31, 2011
  4. Pingback: Access Webservice from Android « Prayag Upd on August 8, 2011


  1. Jon
    October 2, 2009 at 07:32

    Hi, This is a great manual, congratulations. I have a problem.

    In I would like pass more items to the view.

    Now is:

    for (Message msg : messages) {

    ArrayAdapter adapter = new ArrayAdapter(this, R.layout.row, titles);

    And I would like pass to the view the title and date, and in row.xml, show two diferent TextView with its design.

    Thanks, sorry my English, I am Spanish.

  2. TRANG
    March 12, 2010 at 07:07

    Hi All !
    i got some problem with running my android application on actual device : (Motorola milestone droid 2.0.1) . Althoug it’s working fine on Virtual Android (I’m using Eclipse, buiding an android application about loadFeed, work with XML from internet, using ANDROID_SAX). I dont know why ? Anybody help me, thank you very much
    I got sample code from this webpage :

  3. raqz
    April 11, 2010 at 03:37

    Hi… I tried using this tutorial to transfer a simple object of mine but unable to do so. I am sure what is going wrong and where..could some one please look at my code placed in

    Any help would be greatly appreciated.


  4. raqz
    April 11, 2010 at 03:43

    sorry.. i am unable to place my code on the server. please just send a mail to, i can send across the code to you. thanks…

  5. biqut2
    May 4, 2010 at 11:21

    I am having difficulty adapting this method to my own xml output. I have successfully went through all of the code and changed the string names and it continues to work on the xml feed provided but when I change the url and the values that it is looking for it stops working. I can use any help you can give as I am still verymuch a novice at this. My xml is as follows:

    Forex UK Real
    Manually trading with custom indicators and $250 starting balance. Strategy is to use ADX crosses on various time frames for entry points and then allowing a custom EA to close out the trades with a profit and limit the risk of a trend change.



    05/04/2010 08:39
    04/11/2010 11:09

    Basel Financial Demo
    Mini Demo account for manual trading.



    04/30/2010 09:34
    04/26/2010 02:35

    Basel Financial

    FXDD Contest Account
    This demo account is for the contest.



    05/02/2010 19:54
    04/27/2010 08:26


  6. biqut2
    May 4, 2010 at 11:21

    EDIT: tags did not show up

    Forex UK Real
    Manually trading with custom indicators and $250 starting balance. Strategy is to use ADX crosses on various time frames for entry points and then allowing a custom EA to close out the trades with a profit and limit the risk of a trend change.



    05/04/2010 08:39
    04/11/2010 11:09

    Basel Financial Demo
    Mini Demo account for manual trading.



    04/30/2010 09:34
    04/26/2010 02:35

    Basel Financial

    FXDD Contest Account
    This demo account is for the contest.



    05/02/2010 19:54
    04/27/2010 08:26


  7. Richard
    June 6, 2010 at 13:23


    The link for code download at IBM has been locked down. Could you give someone a poke over there? (if that’s possible..). If not would it be possible for you to mail me the code? I’d love to look at it within eclipse!

  8. Sang Shin
    August 13, 2010 at 10:00

    My name is Sang Shin. I am the founder and chief instructor of

    I am wondering if I can use this code as part of my Android programming course. Your name will be mentioned as part of the course material.



  9. OneWorld
    August 19, 2010 at 06:27

    Is the parsing process really that slow? I discovered times between 0,6 and 3,5 seconds depending on the parsing engine. But sounds still very slow to me. Do u guys have same delays?

  10. Tom
    September 30, 2010 at 03:25

    I want to push XML data from Android to a web service

  11. Peter
    November 7, 2010 at 20:24

    I can’t live without android at this point.

  12. dorian
    January 10, 2011 at 02:49

    how to parse the XML node with namespaces?

  13. Rohit
    March 2, 2011 at 08:08

    Hi, really very nice tutorial.
    My question is-how to get images from the rss feed xml file and display it in our android application of rss reader.
    please rply in

    Thanks in advance

  14. Chintan Gupta
    May 9, 2011 at 08:11

    Hi,i am getting response from a web service in XSLT format.
    Please help me to parse data in a Listview.
    like full result list view


    package com.webservice;

    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.AndroidHttpTransport;

    import android.os.Bundle;
    import android.widget.TextView;

    public class WebService extends Activity
    /* private static final String SOAP_ACTION = “”;
    private static final String METHOD_NAME = “Logincheck”;
    private static final String NAMESPACE = “”;
    private static final String URL = “”;*/

    private static final String SOAP_ACTION =””;
    private static final String METHOD_NAME = “open”;
    private static final String NAMESPACE = “”;
    private static final String URL =””;

    /*private static final String SOAP_ACTION =””;
    private static final String METHOD_NAME = “close”;
    private static final String NAMESPACE = “”;
    private static final String URL =””;*/

    TextView tv;

    public void onCreate(Bundle savedInstanceState) {
    tv =(TextView)findViewById(;
    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);


    Request.addProperty(”name”, “priyanka”);
    Request.addProperty(”passcode”, “employer2″);
    Request.addProperty(”status”, 1);
    //Request.addProperty(”status”, 0);

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    tv.setText(”Status0 :”);

    AndroidHttpTransport abt = new AndroidHttpTransport(URL);
    {, soapEnvelope);
    //SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
    // SoapObject resultString = ((SoapObject)soapEnvelope.getResponse());
    // System.err.println(resultString.getName());
    tv.setText(”Status1 :” + soapEnvelope.getResponse());
    catch (Exception E)
    E.printStackTrace ();

  15. crysty
    July 30, 2011 at 18:14
  16. krish
    August 30, 2011 at 03:14

    what is the use of default handler in this above example application?

  17. Pamila Spagnuolo
    September 30, 2011 at 08:09

    Awesome post, wish I could come up with stuff like that for my forum, hahaha.

  18. mamatha
    October 31, 2011 at 03:24

    Hai i done webservices in net.I want to pass those webservices in android by using json but i m not getting values in android.Please help me

  19. Satish
    November 9, 2011 at 05:13

    This is awesome!! thanks for sharing with us. you may check out this following url for brief knowledge on how to create android application using XML…

    Thanks !!!

  20. durgesh pathak
    November 11, 2011 at 07:41

    i am new to android please help me how can i feed news from after importing androidxml simple file i am gettimg error my emailid is

  21. Endy
    December 2, 2011 at 18:57

    Thank you very much. If you do not mind, will translate the article into my native language

  22. Vldzlpae
    December 6, 2011 at 07:49

    The manager Nymphet Preteen

  23. Dien Trinh
    December 21, 2011 at 23:33

    Hi, Thanks for your tutorial. I have a question want to ask you. How can I get url link from enclosure tag?
    Best Regards

  24. Dina
    December 29, 2011 at 23:47

    How to parse the XML node with namespaces?

  25. Levon
    January 2, 2012 at 11:52

    Hello, thanks for your post! Its realy helpful!

  26. Omw1135
    February 10, 2012 at 01:16

    Hello, thanks for your post.
    I have a webservice need to login. How can my android App get and set Session Id from login method ? I want to use this Session Id for others calling WS.

    Thanks for advance.

  27. Tejas Chauhan
    February 16, 2012 at 01:36

    hello Sir!

    I want to access web services in android and show data in listview in android, if possible, any one can help me using xml pull parser to use web service.

  28. fashion ugg boots
    April 3, 2012 at 15:44

    Your website is beautiful, which is popular among customers. I’ll come to visit again. Thank you very much!

  29. Jordi
    April 11, 2012 at 03:50

    Many thanks for your code. I’ve used it and it is working fine in my app!

  30. Bmgqgyti
    May 4, 2012 at 20:34

    A packet of envelopes lollitas petits bbs Man she likes being treated like a dog. U can tell she is a whore who does what she is told

  31. SCOOPpokerstars
    June 10, 2012 at 11:00

    I would like to buy 761477 suns please for 971661

  32. Hammad
    August 9, 2012 at 10:53
  33. Charlene
    April 18, 2014 at 23:44

    My coder is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses. But he’s tryiong none the less.
    I’ve been using WordPress on various websites for about a year and am anxious about switching to another platform.

    I have heard excellent things about
    Is there a way I can transfer all my wordpress posts into it?
    Any kind of help would be greatly appreciated!

  34. Daniel
    May 24, 2014 at 13:28

    I’d like to withdraw $100, please spyware spy internet monitoring software
    2. Perform calculations necessary to compound, dispense a

  35. Brooke
    May 24, 2014 at 22:53

    Thanks for calling spyware removal software reviews Develop a chart to show where your preceptor fits into the chain of

  36. freelove
    June 5, 2014 at 18:33

    Who’s calling? mintop minoxidil 2 Biochem. 2003; 14: 288-294.

  37. lightsoul
    June 16, 2014 at 09:34

    Could I have a statement, please? cheap sildenafil citrate A compound is a product that a pharmacist must make by mixing two or more ingredients, and when they are combined, become

  38. Leah
    July 20, 2014 at 04:23

    I’ve got a full-time job british porn mag The guy needs to shut up!

  39. Blake
    July 20, 2014 at 07:26

    I want to make a withdrawal gopher gold slots y The provider has had a previous denial of payment for the service from the

  40. Caden
    July 31, 2014 at 17:37

    Could you tell me the number for ? bad credit loan personal rating Page 5 of 25

  41. dogkill
    August 1, 2014 at 11:53

    It’s funny goodluck coupons for maxalt 7. Use the web address of the EXACT page where the information was found, except for subscription

  42. Liam
    August 1, 2014 at 18:11

    How do I get an outside line? signature loans online poor credit will be returned in the Authorization Number field. Please

  43. Victoria
    August 2, 2014 at 05:52

    I’m a partner in school essays 1 20-20 Space used to separate fields

  44. Aaron
    August 2, 2014 at 05:52

    Canada>Canada biology report samples are a few examples of when this will occur:

  45. Vanessa
    August 2, 2014 at 05:53

    Good crew it’s cool :) help writing a essay being claimed. If the service is covered or if the provider does not know if the

  46. Parker
    August 3, 2014 at 00:56

    Can you hear me OK? do my homeworknet  Waive a restriction that would otherwise apply, such as a maximum quantity per

  47. Payton
    August 3, 2014 at 22:53

    This is the job description i need help writing my personal statement Procedure Section: Fields 15 to 24

  48. Allison
    August 4, 2014 at 08:58

    We’re at university together where can i find someone to write my term paper steps are appropriate for patients receiving new medications or returning for refills:

  49. Liam
    August 4, 2014 at 08:58

    Have you read any good books lately? best essay writing software standards, the Pharmacy and Therapeutics Committee and other pharmaceutical

  50. Terrence
    November 18, 2014 at 00:26

    Could I borrow your phone, please? limovan 7 5 mg comprimidos The Finn, who will rejoin Ferrari next season after leaving them in 2009 and spending two years out of the sport, opted to pit on lap 26 under the safety car and expertly managed his tires to finish the 61 lap race without any further change.

  51. denver psychic
    March 8, 2015 at 01:14

    Hi every one, here every one is sharing these kinds
    of know-how, thus it’s fastidious to read this webpage,
    and I used to visit this blog all the time.

  52. Casey
    July 14, 2015 at 22:17

    Cool site goodluck :) how many 400mg ibuprofen can i take in a day While overall security at so-called soft targets like sports arenas, hotels, restaurants, movie theaters and housing complexes has increased dramatically in recent years, Saturdayâ??s mass shooting in Nairobi should have an immediate impact among those who safeguard such commercial and residential locations.

  53. Harley
    July 14, 2015 at 22:18

    Your cash is being counted montelukast sodium tablets bp monograph 2013 - In March U.S. prosecutors charge Michael Steinberg, atop executive at SAC, with insider trading in shares of computermaker Dell Inc and chipmaker Nvidia Corp that generatedabout $1.4 million in illegal profits. He is the most senior SACemployee to be indicted in the probe. He pleads not guilty.

  54. Damien
    July 14, 2015 at 22:18

    I need to charge up my phone lasix 20 mg price “I got a chance to be back at home where it all started,” Young said. “I just got a chance to be with my family. I’ve been enjoying life and staying ready. I’m just happy about this opportunity, that I got a call to come in and try to reach and finish off my career like I want it to be.”

  55. Larry
    July 19, 2015 at 06:54

    Gloomy tales accutane prices sri lanka The 11-day battle against the advancing flames has strained the tourism economy of the region at the height of the summer recreation season, and the improving weather conditions were cause for cautious celebration in Hailey, a city of 8,000.

  56. Online Betting info
    August 30, 2015 at 22:04 free bet bonus code

  57. Jordan
    October 2, 2015 at 19:04

    Get monetary savings: read our suggestions how one can get the perfect deal at?a luxury hotel just like the
    4 Seasons Koh?Samui (and/or obtain many free perks).

    October 10, 2015 at 22:34

    Desmond: As only 1 team can rent the break villas whenever you want I would personally state our phillosophy is the best referred to as slimplistic deluxe.

  59. Rafaela
    October 11, 2015 at 07:12

    Excellent website. Plenty of helpful information here.
    I am sending it to several friends ans also sharing in delicious.

    And of course, thank you in your effort!

Leave a comment

Standard Login



  • suck black dick spring thomas
  • good galleries
  • pussy on the mat
  • from vintage movies
  • rap video nude interracial
  • black girl naked in public
  • emily blunt lesbian sex
  • homemade video of wife and i
  • two girls rubbing breasts
  • Girl sex vedio
  • nice little plump pussy
  • nude beach sex pictures
  • facesitting teen threesome ffm picture
  • erotic threesome sex tapes
  • upcoming movie auditions for teen girls
  • mature black chicks white
  • bizarre cock going through pussy
  • shawnee girls nj naked
  • lubetube african girl get fuck
  • nude young boy sex
  • very young little girls
  • free arab pussy
  • mtv girls naked
  • free premium long video
  • ameteur sex movies free
  • pain that pussy
  • free amateur group sex videos
  • free amateur women videos
  • anal thumbnail pics
  • Lauren anderson nude pics
  • public fingering pussy
  • my little asian pix free
  • Girls next door fuck
  • young sexy girls model
  • Lesbian sex scenes movies
  • hot sexy naked lesbain hardcore
  • Hot christian girls
  • sextube old lick
  • wife guys masterbating to pics
  • free shiny angel girl
  • Indian girls sex photos
  • free teen erotica galleries
  • teen nonnude gallery
  • japanese women love black men
  • Lucy pinder nude movie
  • asian anal cum scenes
  • free videos online young girl
  • black girl interracial facials pics
  • wife has a secret girlfriend
  • Squirt teen free
  • erotic nudist galleries
  • mature solo big boob videos
  • hardcore orgie
  • video orgasm close up
  • best pussy liking tube
  • teen legal pussy
  • nude black teen virgin video
  • teen girl brands
  • mature slut redhead shaved pussy
  • amateur british girls
  • abused teen sex gallery
  • first time anal trial video
  • wild group fucking sex movies
  • dickand pussies with tits
  • girls with bubble butts
  • real amature teen lesbians
  • anal ass videos
  • young ebony small cunts videos
  • pics auditions
  • stories wife forced threesome
  • pictures of the wife of bath
  • black girls tease tubes
  • couples pleasing eachother sexually
  • huge cock and tight pussy
  • mega teen couples
  • Cars and nude girls
  • smallest pussy vol
  • asian orgy party
  • sleeping beauties tube
  • husband suck tits video
  • asian girl
  • free amateur videos of somes
  • black girls cucking dick
  • blonde moms on black
  • Van nuys teen clinic
  • anime hentai tit pussy
  • Hairy indian nude
  • naked girl cookie cutters
  • naked teens straight guys
  • girls with big boobs spread vagina
  • young black and honey
  • bikini girl pics gallery
  • petite jean bermuda short
  • unshaved amateur wives
  • sexy lesbian feet and tits
  • girl on girl pussy juice
  • Porn to make you cum
  • interracial office fuck pics
  • xhamster russian sons fuck mum
  • young taboo erotic stories
  • Big boobs site
  • stickam young girls
  • la petite baleen ca
  • keez movies tight asian mikko
  • teen girls masturbating with dildos movies
  • teen sex oral large breasts
  • big dark nipples movies
  • pussy close up hairy
  • teen fingers then has orgasm
  • naked people picture artist
  • free video older women
  • black cock in my wife amateaur
  • Orgasmic pussy licking
  • girls with big boobs fucking
  • clothed unclothed gallery mature
  • streaming sexy teens
  • pussy ass and huge tits
  • crying anal video
  • black upskirt shemale
  • show your own video sex
  • girl gets hardest fuck screaming
  • nude girl action video
  • hardcore big dicks
  • step fathers pounding doughters pussy xxx
  • african gynastic black muscle girls pic
  • naked teen panty
  • office lesbian interracial
  • why would my pussy squirt
  • free streaming sex viral videos
  • naked girls black
  • girls from house hardcore
  • sexy mature secretary
  • young girl solo masturbation
  • big black naturals
  • Hot teen pussy getting fucked
  • huge black dick pictures
  • shit on dick when anal video
  • amateur home teen video
  • massive black ebony boob
  • latino ass movies
  • wife sex group
  • young teens with old men
  • free black and white movie downloads
  • Cuba girl sex
  • tied up amateur videos
  • Girls like anal
  • latina singer video noelia
  • asian fisting galleries
  • boat party florida naked
  • drunken girls at party
  • erotic black sca ns
  • free video xxx young teens
  • Naked philippines girls
  • video teen grinding