Andy Andy - 25 days ago 14
Android Question

xml parsing through variable file name

I have some xml files, and I keep them in

raw
folder. Now, the problem is that I have to use them with
variable name
according to my application condition. But I don't know how to fetch them. The main thing is that I am not getting that how to give the path of my xml file in application.

For example:

My file
application.xml
is stored in the
raw
folder and I have to access it with a variable name.

String xmlName = application.xml;


How can I fetch my xml through
xmlName
variable?

Answer Source

Its not right practise to keep your general xml files in res folder. put those in assets folder. make assest folder at the same level where res folder is there in your project. Create your [name].xml file there.

access it as

InputStream in=getAssets().open("[name].xml"); String xml=convertStreamToString(in); and then use this string variable