0

While doing this I followed this tutorial. It parses XML well, but from URL. I need to change XML source to R.xml folder.

ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element`

How to change String xml = parser.getXmlFromUrl(URL); line of code so that XML will be taken from R.xml folder?

sandrstar
  • 12,503
  • 8
  • 58
  • 65
Joe Rakhimov
  • 4,713
  • 9
  • 51
  • 109

2 Answers2

1

First of all, create a folder /res/xml, and our own XML file myxml.xml.

Then you can open it using:

Resources res = activity.getResources();
XmlResourceParser xrp = res.getXml(R.xml.your_resId);

You can follow this post.

rahulserver
  • 10,411
  • 24
  • 90
  • 164
0

If your xml file is in res/xml please see http://developer.android.com/guide/topics/resources/providing-resources.html. Another option would be to place your file in the asset folder, then you can access it like described here How to get URI from an asset File?.

It's not clear from your question what exactly your problem is. If none of the above options is for you please specify your requirements a little bit more.

Community
  • 1
  • 1
André Diermann
  • 2,725
  • 23
  • 28