How can I parse my local XML file located in my android project (inside res/XML folder) and want to get the values in that file.
Asked
Active
Viewed 1.1k times
5
-
You can check this link too http://stackoverflow.com/questions/9915219/parse-a-local-xml-file-and-store-in-sqlite-database-in-android – surhidamatya Sep 18 '12 at 10:36
-
http://stackoverflow.com/questions/5702729/store-parsed-xml-data-to-sqlite-android check this too.it may help you – surhidamatya Sep 18 '12 at 10:39
2 Answers
10
To access XML resources stored in res/xml
, call getResources().getXml()
from any Activity
or other Context
. You need to supply to getXml()
the ID of the XML to load (R.xml.myfile
).

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
6The getXml() method automatically returns you an XmlResourceParser implementation instance, so you can directly pass it to XmlPullParser and start parsing your data. – Dimitar Dimitrov Sep 03 '09 at 11:50
4
to read your xml add code as shown below
XmlResourceParser myxml = mContext.getResources().getXml(R.xml.MyXml);
//MyXml.xml is name of our xml in newly created xml folder, mContext is the current context
// Alternatively use: XmlResourceParser myxml = getContext().getResources().getXml(R.xml.MyXml);
myxml.next();//Get next parse event
int eventType = myxml.getEventType(); //Get current xml event i.e., START_DOCUMENT etc.
and to get content of code add code shown below

Hans Olsson
- 54,199
- 15
- 94
- 116

Khan
- 7,585
- 3
- 27
- 44