解析在Android的SQLite数据库本地XML文件和存储

编程入门 行业动态 更新时间:2024-10-25 12:21:44
本文介绍了解析在Android的SQLite数据库本地XML文件和存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想任何人告诉我如何读取本地XML文件(maths.xml)和一个解析器解析它,然后获得存储到数据库sqllite(maths.db)的信息code和之后如何查询数据库对于给定的搜索词例如101

例如maths.xml如下:

<数学>< mathametician><&ID GT 101 LT; / ID><名称> K和LT; /名称><年龄> 75℃/年龄>< / mathametician>< mathametician><&ID GT; 102 LT; / ID><名称>&大卫LT; /名称><年龄> 62 LT; /年龄>< / mathametician>< /数学>

解决方案

把你的XML文件导入到资源文件夹,你可以得到的输入流的形式XML

的InputStream原料= context.getApplicationContext()。getAssets()。打开(                    maths.xml);

您可以通过分析不同的解析器像SAX此xml,大教堂这里是DOM帕西小code

文档DOM = builder.parse(生);元根= dom.getDocumentElement()节点列表mathametician = root.getElementsByTagName(mathametician);

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

和插入您的数据DB,你得到了XML标签

I would like anybody to show me the CODE on how to read a local xml file (maths.xml) and parse it with a parser and then store the information obtained into a sqllite database (maths.db) and after that how to query the database for a given search word example "101"

for example the 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>

解决方案

put your xml file into asset folder and you can get xml in form of input stream

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

you can parse this xml using different parser like SAX,Dom here is small code of dom parsee

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

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

and insert your data to db as you got tag from xml

更多推荐

解析在Android的SQLite数据库本地XML文件和存储

本文发布于:2023-10-07 10:41:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   文件   Android   SQLite   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!