How to get xml file from drawable folder Android

Issue

I have an xml file on a web page http://api.androidhive.info/music/music.xml on my application I use

static final String URL = "http://api.androidhive.info/music/music.xml";
String xml = parser.getXmlFromUrl(URL);

works fine but know I have put this file in my Android resource folder. So how do I get my file from android drawable folder like this R.drawble.music.xml instead of web page.
http://api.androidhive.info/music/music.xml

Solution

Put the xml into /res/raw folder.

Then use :

InputStream is=getResources().openRawResource(R.raw.my_xml);

Then use this parser XML PULL PARSER

XmlPullParser xpp=XmlPullParserFactory.newInstance().newPullParser();
xpp.setInput(is,"your-encoding");

Thanks.

Answered By – Pratik Sharma

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published