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.

Leave a comment

Standard Login



  • ass to mouth wives
  • pussy sucking hardcore
  • teen eats lesbian ass
  • free young hairy girls
  • The black ass
  • young couple blowjob redtube
  • long flash player videos
  • free amatuer house wife nude pics
  • year old br girls video
  • slow fuck pussy
  • naked women exercising pics
  • nature in pussy
  • girls teens naked
  • free video to download
  • you couples
  • petite brunette fuck
  • sora aoi suck dicks
  • pictures of unshaven black vaginas
  • free pictures of naked policemen
  • nude school girl sex
  • interracial blond black stockings
  • download black teens
  • Hot teacher has sex with student
  • monroes beauty salon blackwood gwent uk
  • free asian sex streaming videos
  • young girl panty models
  • party girl upskirt video
  • the ramen girl japanese version dvdrip
  • tera patrick futuristic pussy
  • Sex videos of indian
  • playboy sex wives
  • anal xxx tube
  • Latin lesbian movies
  • anal bloopers videos
  • Hot girl touch
  • two girls and a guy threesome
  • movie sex and zen
  • nude young girl models
  • group fuck pics
  • lesbian pool table pussy cue
  • videos of guys fucking teens
  • mature women and young me
  • barbie doll sex videos
  • party sex free vids
  • teen asian nude girls
  • new blowjob
  • mature girls org
  • amateur sex movies college
  • Amanda holden sex vid
  • mature eboney sex free thumbnails
  • teen couple hardcore vids
  • Home sweet sex
  • movie with romantic sex scene
  • lolo ferrari tits video
  • free shaved xxx videos
  • black reigns movie
  • free asian ass pics
  • young girl foot lover
  • naked girls shaking there ass
  • xxx hardcore lesbains
  • equal rights topless houston pics
  • Bo derek nude movies
  • black girl jpegs
  • slimy teen pussy
  • Gaping wet pussy
  • girls gone wild fingering box
  • hot wet sex wives bombshells
  • Anna falchi sex scene
  • milfs fuck big dick
  • myles hernandez sex videos
  • asian fortune cookie sex
  • free new couple orgasm videos
  • spanked ass galleries
  • big booty black girl pics
  • free videos extreme objects
  • hardcore teen black
  • amateur straight guy sex
  • hottest different boobs pics
  • anal strapon girl on girl
  • Nude pics of morgan webb
  • teen girl flesh
  • Sex hollywood scene
  • teen topanga free movie
  • inexperienced girls sex
  • teen girl sex tube videos
  • hardcore asians video
  • pussy fuck vids
  • See girls breast
  • mickie james naked videos
  • wife sexually put in her place
  • ipod pussy whipping
  • red hair pale pussy
  • howto guide to anal sex
  • girl three dicks
  • free pussy pictures mature
  • free handjob mlif videos
  • bologna italy oral sex
  • videos amateur gratis de folladas
  • black lesiban mom sex tube
  • young virgin pussy teen models nonnude
  • teen celeb bikini
  • mr big dicks hot chicks stars
  • best handjob videos
  • free homemade streaming college sex videos
  • star cumshots on tits compilation
  • hardcore strapon lesbian video
  • Ebony ass movies
  • pretty blonde girls free videos
  • cfnm fucking black stripper free movies
  • free amateur female masturbation videos
  • free erotic lesbian video
  • interracial deep pussy
  • hardcore fucking free
  • rough oral sex
  • free big tits schoolgirl pictures galleries
  • homemade movies perky slender blonde
  • Hot teen girls
  • hairy teens youngest sex movies
  • Naked teen sleeping
  • girls naked sports nude
  • free hardcore pictures or galleries
  • naked college girls party hardcore
  • asian girls video thumbs
  • college fuck party in texas
  • ebony sex redtube
  • young asian teen girls
  • free streaming black videos
  • sexy black fringe top
  • wife pussy finger
  • Psp sex
  • naked men photo gallery
  • sexy surfer girl galleries
  • rubbing ass on dick
  • free interracial slutwife gangbangs
  • amateur wife cream free
  • giant cock and pussy
  • Bbw interracial videos
  • Fuck sex video
  • sexy girl blowjob
  • free mmf femdom videos
  • men on one girl
  • small dick chicks
  • housewives ass fucked
  • nude korean school girls
  • esperanza gomez sex videos
  • free mature swinger vids
  • top movie reviews
  • Naughty america threesome
  • degrassi stars with bikini pictures
  • black hair
  • group of cocks fuck one pussy
  • erotic clothing in public pics
  • sexy college girl nudity
  • shego sex videos
  • Sex images of kareena kapoor
  • white black
  • oral sex swollow cum
  • Hot masturbation video
  • shaved anal sex
  • christmas anal sex
  • free movies of young girlies
  • movies glamour blondes glasses
  • free nude sex tube movies
  • Amateur big tit movies
  • petite young nude
  • Lesbian feet pics
  • really young teen pussy
  • big free pussy pics
  • soft lesbian kissing tits
  • lesbian shemale free
  • perfect body tits boobs pussy video
  • you tube mature sex free
  • hairless pussy women
  • Naked gf pic
  • lesbian mature you
  • youngest teenage
  • yonger babes video
  • hardcore black men male
  • Beach naked girls
  • Sex video in the philippines
  • Nude photo girls
  • call girl sex video
  • thick black anal sex
  • whp is the hottest black star
  • free s video
  • little chicks doing big dicks
  • webcam girls contacts sex
  • video post amateur sex wife sucking
  • free online teen galleries
  • video missionary sex
  • Hot naked chicks
  • young pink shaven pussy
  • Every hot girl is a rockstar
  • free watch movies tubes
  • Edison chen sex photo gallery
  • brazilian ass pussy
  • young teen moaning
  • naked gaping pussy
  • free teen sibling vids
  • sex pill for girls
  • a girl like you movie
  • black ebony sexy erotic videos
  • free chinese girls naked videos
  • Teens ass and tits
  • naked celelbrity pics
  • young girls shit
  • skinny black pussy free vidoes
  • firewall test young lesbian cunt play
  • miley cyrus look alike blowjob video
  • pics of sex beaches
  • girls ass smell
  • free nude chubby mature galleries
  • asian petite torrent
  • young stud bangs mature girl
  • Nude videos of amisha patel
  • china girl tube
  • old man fucks young girl videos
  • black girls nake
  • plump amateur girls
  • oral sex numbing
  • very little black girls
  • pussy movie fayetteville nc
  • Sex girl egypt
  • nude blackbook babes
  • young amandas sexual pictures
  • sex starved blonde
  • internet web sites on teen sexuality
  • busty interracial bbw video tube
  • sexy teens sexy teens wallpaper
  • naked teen amateurs
  • pictures of mature older sexy women
  • sexual dominance wife
  • free video gallerys sites
  • naughty young teen girls
  • free xxx redhead pussy pics
  • free pure teen galleries
  • asian black interr
  • Nude katrina kaif images
  • interracial fmf video
  • skinny teens fucking videos
  • free hot girlfirend fuck video stream
  • unreal anal videos
  • Hot anal teen
  • shemale sex vidios
  • watch linsey dawn mckenzie hardcore videos
  • tits and women pictures
  • free mature amatuer pics gallery
  • pussy eating competition
  • Oriental sex pictures
  • anal tube home videos
  • glamour forums girlfolio
  • young cock holds mature mom
  • open that little pussy up tube
  • naked girls doing flips
  • blonde fucked by black cop
  • redhead movies creampie
  • hot black babes stripping
  • black anal sex images
  • girls fucking guys cuckhold videos
  • sex machine squirting videos
  • ebony foot models videos
  • mature lesbian pictures free archives
  • mature couple sex videos
  • blach xxx teen ass
  • black bra lesbian thumbs
  • petite black teens
  • old naked men on men pictures
  • cleopatra sex movie
  • asian teens interratial sex
  • mans dick in mans ass pictires
  • best ass girl
  • Fucked up anal
  • pictures young teens
  • hustler black ass
  • sexy mexicana teens
  • hot roxy mature video
  • petite anal vids
  • video celeb
  • hot black girls stripping
  • adrienne naked pics
  • girls shaving their fanny pics
  • clit fingering girlfriend
  • amateur moview
  • star jayden james anal