In my previous post I linked to a terrific website (Working with XML on Android) which describes how you can read and parse XML documents in Android. The code supplied by that website used polymorphism to show 4 different methods for parsing the XML data. I vowed to simplify that and share the new source code.
To download the AndroidXmlSimple project click here. You will be taken to another page where you can click to download to the ZIP file.
Below are some instructions on setting yourself up with this source code and customizing it for your own XML data.
1. Download the file AndroidXmlSimple.zip
2. Unzip it on your disk.
3. Open Eclipse and import the Android project into your workspace.
4. The project will look like this:
5. This new project opens up an XML document (the same RSS feed as the original example) and displays it using a ListActivity.
6. The classes are:
- MessageList.java: the main Activity
- Message.java: object that stores the parsed XML data
- RssHandler.java: object that parses the XML data
- BaseFeedParser.java: object that initiates the starting point and configurations for the XML data that should be parsed.
7. To customize this project for your own feed, edit the file BaseFeedParser.java.
Update the URL location here:
static String feedUrlString = "http://www.androidster.com/android_news.rss";
Update the hierarchy of nodes here:
static final String RSS = "rss"; static final String CHANNEL = "channel"; static final String ITEM = "item";
Update the node names that repeat here:
static final String PUB_DATE = "pubDate"; static final String DESCRIPTION = "description"; static final String LINK = "link"; static final String TITLE = "title";
And as in the previous post, if you change any names of the constants, you will need to update other sections of the code-base, for example below in BaseFeedParser.java, and in a few places in RssHandler.java.
item.getChild(TITLE).setEndTextElementListener(new EndTextElementListener(){ public void end(String body) { currentMessage.setTitle(body); } }); item.getChild(LINK).setEndTextElementListener(new EndTextElementListener(){ public void end(String body) { currentMessage.setLink(body); } }); item.getChild(DESCRIPTION).setEndTextElementListener(new EndTextElementListener(){ public void end(String body) { currentMessage.setDescription(body); } }); item.getChild(PUB_DATE).setEndTextElementListener(new EndTextElementListener(){ public void end(String body) { currentMessage.setDate(body); } });
Please leave a comment if you download this ZIP file – I’d like to know if you found this useful. And let me know if it does what you expected after reading my post. Thanks!

August 11, 2009 at 08:35
Very nice try and good example!
Unfortunately it works only for RSS 2.
RDF does now work, and it’s too common…
October 18, 2009 at 15:07
hello I read posts from kml and put them into a listview someone help me know
December 19, 2009 at 02:31
You code is superb!.
But a little bit hard for beginners.
You can write a tutorial itself with those code.
I am waiting for that. ( a little bit code explanation )
Keep the good work on.
January 16, 2010 at 14:17
Hey thanks for the code it helped me A LOT.
I’m making an app for Android that uses a few webservices and your simple code works. It saved me a lot of time.
Anyways, I have a question.
One of my webservices don’t work. Or better said, I can’t seem to get it to work
It’s this webservice:
http://www.pathe.nl/export/export.asmx/HaalAgenda?filmId=0&biosId=6
Can you (or someone else) tell me how I can parse this kind of webservice (cuz this is not a regular XML-service)
Thanks in advance!
Galip
January 25, 2010 at 14:59
Thanks for publishing that. I’d found the IBM page before and this did indeed make it that bit simpler. I haven’t been able to run the code yet as I’m at work and fighting with the Android emulator to get it through the proxy. This did however lead me to try making the XML file local (which is my final aim anyway) as res/xml/android_news.xml and tried loading it by using:
Xml.parse(appContext.getResources().openRawResource(R.xml.android_news), Xml.Encoding.UTF_8, root.getContentHandler());
The debugger tells me it’s not well formed. Googling around for solutions at the moment but it seems everyone loading local files uses getResources().getXml(blah) and uses a PullParser.
If you’ve got any advice I’d love to hear it. Thanks again.
February 2, 2010 at 23:27
I have a question, i working on a currency exchange.
So i need to the live data of different countries..
So how shall go about to extract out the value of it?
Email me: shiqin02@hotmail.com
February 23, 2010 at 13:41
I am in the same boat as Felicia. She needs to extract live currency info, I need to extract live stock quotes. I do it with biterscripting ( http://www.biterscripting.com ). Google up “biterscripting stock price” and it will find lots of scripts people have written. Hope this helps.
February 27, 2010 at 08:04
I cannot download the zip-file, can you fix the page?
Warning: Cannot modify header information - headers already sent by (output started at /home/warrlou2/public_html/blog/downloads.php:8) in /home/warrlou2/public_html/blog/downloads.php on line 76″
February 27, 2010 at 18:23
Sorry about that, I will try to fix it.
February 27, 2010 at 19:12
Ok, the button should be working now. Thanks for notifying me of this!
March 17, 2010 at 06:33
code is very good …
and it help me a lot..
but in this code if want to change web address then will we have to change hierarchy of nodes.. and how can i find out the tag names in site which is subscribe to getting news. like here pubdate, description, title etc..
thanks and if u have solution plz mail me
March 25, 2010 at 05:07
HI,
Code is very useful but i have a doubt. If the XML file contains the attributes like
How do we write the BasefeedParser in the List parse parse() method .
Here , it can retrieve the content anything between the tags like content
Please help asap.. Thanks in advance..
April 11, 2010 at 20:01
This is very helpful as I’m trying to make an kuler (adobe) for android, but how can I pass a picture to the RSS feed and the message list?
http://kuler-api.adobe.com/rss/get.cfm?listtype=recent&key=E476E7121D5776A8831DAA6476DE8837
April 19, 2010 at 07:35
Does this also parse the “cdata” ? As a matter of fact i tried it but it is not supporting cdata tags . Can you suggest any modifications so as to parse the “cdata” tag also
thanks
April 28, 2010 at 15:07
Great Tutorial! Got me up and running in less then 15 minutes. Exactly what I’ve been looking for!
April 28, 2010 at 19:01
Hi!
Thanks for this code, I’ll try to adapt it to a slightly different XML structure.
Allthought that, something weird is going on when I try to run this code without modyfing it.
In a Virtual Emulator on th ePc it’s ok, but when I run it on an Android Device directly the List can’t be load.
I activated the debug mode and this is what comes up:
04-29 00:58:12.707: ERROR/AndroidNews(10820): Caused by: java.lang.RuntimeException: java.text.ParseException: Unparseable date: Tue, 24 Nov 2009 01:50:21 +0100
04-29 00:58:12.707: ERROR/AndroidNews(10820): at com.warriorpoint.androidxmlsimple.Message.setDate(Message.java:57)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at com.warriorpoint.androidxmlsimple.BaseFeedParser$5.end(BaseFeedParser.java:77)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at android.sax.RootElement$Handler.endElement(RootElement.java:197)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:159)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at org.apache.harmony.xml.ExpatParser.append(Native Method)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at android.util.Xml.parse(Xml.java:87)
04-29 00:58:12.707: ERROR/AndroidNews(10820): at com.warriorpoint.androidxmlsimple.BaseFeedParser.parse(BaseFeedParser.java:81)
04-29 00:58:12.707: ERROR/AndroidNews(10820): … 15 more
Don’t know whats the matter about it ^^’. If You could tell please. thanks!
May 25, 2010 at 08:40
Thanks a lot! It really helped me.
One hint maybe:
Xml.parse(this.getInputStream(), Xml.Encoding.ISO_8859_1, root.getContentHandler());
if your are trying to parse ISO
May 27, 2010 at 04:41
HI,
CAn anyone help me how to extract the attribute values in the XMl file. I’m able to retrieve the normal data inside the tags but i need for the like example below:
i want to extract the value kevin and age value 20. how to modify the item code for the same????
July 15, 2010 at 19:52
Can Someone please show us how to extract attribute values?!?!?! I have been trying to learn java for android and this is the farthest i have gotten. Please someone post how to!
July 15, 2010 at 22:06
Well i downloaded your code however eclipse complains
Project has no default.properties file so i can’t use your simplified version luckily enough i’m a good enough programmer to yank out everything except the SAX code and make it work…..you should simplify all 4 parse methods as they all have a use in one use case or another.
August 6, 2010 at 04:54
Hi,
I found this article extremely helpful. Thanks for that. I had a very painful problem though.
In the message.java you are using
static SimpleDateFormat FORMATTER =
new SimpleDateFormat(”EEE, dd MMM yyyy kk:mm:ss ZZZZ”);
That could cause problems on none US devices.
This worked:
static SimpleDateFormat FORMATTER =
new SimpleDateFormat(”EEE, dd MMM yyyy kk:mm:ss ZZZZ”, Locale.US);
Regards,
Rob
September 11, 2010 at 05:43
Hii.. ur post is superb.. i downloaded and it work fine.. but when i try to do by my own by using the site http://finance.yahoo.com/, i got stuck.. i want to retrieve some data from there.. please help me how should i proceed.. help me with some code..
Thanks..
September 14, 2010 at 02:39
@GreenRob Really necessary your change! Until i changed the formatter declaration the program didnt worked. Thanks ^^
September 27, 2010 at 10:28
Great Job.. Keep it up..
October 4, 2010 at 13:06
Hey thanks a lot for the method, it really took a while for me to model it for my own file. Was very helpful though!!
Kudos!:D
October 6, 2010 at 05:22
It doesn’t work for me, I downloaded the code, imported the project in Eclipse Galileo, exported the apk and run in my Device (Htc Desire 2.2), but nothing happens…I only see the title of the app and a blask background…
October 10, 2010 at 03:50
hello i download and try it on emulator what it shows me only blank page on emulator what should i do now kindly reply me as soon as possible
October 10, 2010 at 04:01
same problem with me as david manca having kindly tell me
October 22, 2010 at 14:18
where is the code?
November 2, 2010 at 07:13
Hi,
I have just downloaded the code and imported the project to directory.
I am trying to run the project but it doesn’t gives any output gives just a blank screen.
what could be the reason?
kindly tell.
November 12, 2010 at 03:41
how to grab enclosure tags?
like:
November 15, 2010 at 12:50
I think your rss url is broken
static String feedUrlString = “http://www.androidster.com/android_news.rss”;
November 25, 2010 at 01:49
hi,this is a great sample ,but i am trying to call this in the second view in my app, but not able to load to listview,could you help me out please
November 26, 2010 at 05:14
hi,
I want to parse any XML and display it in listView. I am new in Android devlopment.
me trying this code, I am using android 2.2, but it gives the exception like ” java.net.UnknownHostException:Hpst is unresolverd”
please give me some solution.
Many thanks
Dattatraya
December 12, 2010 at 17:10
thank U
December 17, 2010 at 06:07
hi,
Its very helpful.
I want to develop an app.The main purpose is, I want to store web services data(after parsing) in android sqlite database.
please help me out on this.
Thanks in advance.
December 17, 2010 at 06:09
hi,
Its very helpful.
I want to develop an app.The main purpose is, I want to store web services data(after parsing) in android sqlite database.
Its urgent.please help me out on this.
Thanks in advance.
December 21, 2010 at 02:30
hi
it’s very helpful for me
thanks ^^
January 10, 2011 at 07:12
vasotec
enalapril
enalapril
ACE inhibitor
treatment of hypertension
10 to 40 mg po qd
hypertension, dizziness
lithium, potassium
vasotec
enalapril
enalapril
ACE inhibitor
treatment of hypertension
10 to 40 mg po qd
hypertension, dizziness
lithium, potassium
This is the xml iam trying to parse. Modified the code. But the output is blank. Iam in need to do this urgently please help me/
January 24, 2011 at 22:32
Select the simple patterns on one side of the dress in complementing colors on the rest part.
January 26, 2011 at 21:40
well, that’s a good way to put it up a notch, nice insights works well in clientele explanation and information resource option.
http://www.veloceitservices.com
Apple Mac Repair Frisco
February 9, 2011 at 16:46
I just wanted to thank you. I had to develop an android app without any previous experience in java or mobile apps.
Your code helped me shitloads!!
February 10, 2011 at 13:26
Hi, I’m building a hunting application for which I need weather information in form of a RSS feed from the following site: http://www.meteo.si/uploads/probase/www/fproduct/text/sl/fcast_si-region_latest.rss
I’ve used the code from this site and it list the feeds, but when I click on an item it doesn’t connect it to the site for more information … I would like to get temperture and wind information but I don’t know how to because I’m a beginer to programing.
I would very much appreciate any help especially in form of a code that would solve my problem.
Thanks in advance
February 28, 2011 at 10:28
Eclipse can’t load it as existing project (I get some error that description is not OK or whatever), and thanks to the total lack of comments I’ve no idea what it’s supposed to do…
March 3, 2011 at 06:19
thanks a lot for this tutorial, having big problems here reading feeds, my emulator cannot connect to internet… dunno why
March 7, 2011 at 08:34
nice
March 15, 2011 at 01:15
Hmmmm, seems to only work with the stock feed. ??? why’s that
March 25, 2011 at 14:17
It’s working with a feed I tried: http://gonu.com/rss.aspx?path=mhockey
April 15, 2011 at 06:39
why is the rsshandler class included if it is never used?
April 22, 2011 at 11:29
In the list view I want to bind the data according to the design pattern I have make(Means making another layout and bind it wit the listview)… I didn’t get the procedure mention in your code … so, please guide me.. to.. perform the task… thank.. u for u’r concern…
April 22, 2011 at 23:53
neat, thatnks!
April 23, 2011 at 04:29
04-23 14:04:54.197: ERROR/AndroidNews(3127): android.sax.BadXmlException: Line 1: Root element name does not match. Expected: ‘o31′, Got: ‘http://schemas.datacontract.org/2004/07/VTrakPOD.DTO:o31′
April 23, 2011 at 04:29
04-23 14:04:54.197: ERROR/AndroidNews(3127): android.sax.BadXmlException: Line 1: Root element name does not match. Expected: ‘o31′, Got: ‘http://schemas.datacontract.org/2004/07/VTrakPOD.DTO:o31′
April 26, 2011 at 12:25
Thank you very much. i need help to extract restaurants from the list in the given web site. is it possible to extract?
It help me a lot
May 23, 2011 at 11:33
Hi,
I found your code very useful for my project… However, how can I store the xml file (on a specific folder such as raw or something else within /res) and then load it from there and not from the net?
Thank you
May 24, 2011 at 03:16
hi thanks for the code it helped me a lot.
i have a question. how i open description on click on title?
actually i want to take print out of description when i click on a particular title. Please help me.
thanks in advance.
May 25, 2011 at 03:46
hi thanks for the code it helped me a lot.
how i open description on click on title?
please replay at rajinder4981@gmail.com
July 11, 2011 at 16:32
I discovered your own blog site on the internet and check several of your earlier posts. Still keep in the really good run. I just additional your Feed to my personal MSN News Readers. Looking for toward reading more from you later on!?-
July 18, 2011 at 05:30
i want to parse
http://www.kompas.com/getrss/all
but with your code it didn’t show anything
July 19, 2011 at 05:17
Thanks a lot it has been very useful spending a time on work it really helped …..hope to get more from you for the Android beginners ….:)
August 9, 2011 at 20:14
Hands down the best RSS/XML tutorial on the web, trust me, i’ve tried them all and ran into a lot of issues to the point I was just going to give up. This code is solid! I suspect you write books or something, because as a beginner, i could actually follow this
August 12, 2011 at 09:15
cool man! definately a great point of start for XML and Android!
August 23, 2011 at 22:10
Hi bro,
Pls give me your download link. This post is very useful for me(android beginner).Thanks .
respectfully,
kyawswarthant(@myanamr)
August 23, 2011 at 22:13
Hi bro,
sorry, I see your download link.
thanks
September 29, 2011 at 09:13
Good work but it is too hard to follow for newbies. Kindly provide some explanation also..
Thanks
October 24, 2011 at 19:26
i cant see anything on the list
October 28, 2011 at 13:30
This works great for me but I am having a problem when trying to read tags. The code does not process the line of data. Is there something simple I’m missing?
October 28, 2011 at 13:38
update: that was supposed to be that I’m having a problem reading content:encoded tags.
October 31, 2011 at 22:32
awesome article!! thx lot.. it worked perfectly!
November 11, 2011 at 08:14
after importig androidxmlsimple project i am getting error in
MessageList.java RssHandler.java: BaseFeedParser.java: please help me
November 23, 2011 at 04:38
cheers mate, it’s good to have some working XML-handling code (just compiled it and it runs fine…) as a basis to work from. was really getting stressed with some other code example that i could not get to work!
@Durgesh i too had a bit of hassle. what fixed it for me was right clicking on the project, selecting “Properties” and ticking a box in Android properties that corresponded to my build platform of choice.
December 6, 2011 at 07:07
hi,it’s a very good tutorial but i cannot resolve those errors that i faced I’m too much confuse that my web service is made of php so i save the XML file in wamp server that i call in android as a client that i used parse the xml data in table form give give me the code that how i parse the xml data in table form.
and please explain the function of below line:
static String feedUrlString = “http://www.androidster.com/android_news.rss”;
December 18, 2011 at 06:14
I have a proxy server that prevents normal connections to go out to the internet, what would i have to add? ;\
January 9, 2012 at 09:01
Hi. I am an Android newbie, but found this article really interesting. However, when I import AndroidXmlSimple into Eclipse Indigo, I get this error: Unable to resolve target ‘android-3′. I have the Android SDK Platforms from 2.2 to 3.2 installed and Eclipse shows that under the Android SDK and AVD Manager. Any ideas? Thanks.
January 9, 2012 at 10:08
Ok. I solved it by changing ‘android-3′ to ‘android-8′. Thanks.
January 11, 2012 at 02:42
i hav a problem ..it shows me error when i did as you said
January 17, 2012 at 20:37
cool
February 4, 2012 at 22:09
thank you !!