Parse the local XML file and store it in the sqlite database on Android

I would like someone to show me CODE on how to read a local XML file (maths.xml) and parse it with a parser, and then store the information received in sqlite database (maths.db), and after this to query the database for this example search word "101"

for example maths.xml is as follows

<maths> <mathametician> <id>101</id> <name>kurt</name> <age>75</age> </mathametician> <mathametician> <id>102</id> <name>david</name> <age>62</age> </mathametician> </maths> 
0
android xml sqlite
source share
1 answer

put your xml file in the resource folder and you can get the xml as input stream

 InputStream raw = context.getApplicationContext().getAssets().open( "maths.xml"); 

you can parse this xml with another parser like SAX, Dom here is a small dom parsee code

 Document dom = builder.parse(raw); Element root = dom.getDocumentElement() NodeList mathametician = root.getElementsByTagName("mathametician"); 

for (int i = 0; i <mathametician.getLength (); i ++)

and paste your data in db when you got the tag from xml

0
source share

All Articles