2012-02-21 174 views
1

我有一个xml格式的数据来自服务器。现在我想将它存储到数据库中,并且它应该加载按钮单击。我应该怎么做?如何将XML数据存储到SQLite数据库

enter code here 

<qst_code> 7 </qst_code> 
<qst_prg_code> 1  </qst_prg_code> 
<qst_mod_code> 2 </qst_mod_code> 







<qst_Question>What is not true about left dominant cardiology circulation? </qst_Question> 



<qst_opt1>It is seen in 20% of the population</qst_opt1> 
<qst_opt2>Left circumflex artery supplies the Posterior descending artery</qst_opt2> 
<qst_opt3>Left circumflex artery terminates as obtuse marginal branch</qst_opt3> 
<qst_opt4>Left circumflex artery may originate from right coronary sinus</qst_opt4> 
<qst_opt01>1</qst_opt01> 
<qst_opt02>1</qst_opt02> 
<qst_opt03>1</qst_opt03> 



<qst_opt04>1</qst_opt04> 
<qst_CorctOpt>1</qst_CorctOpt> 
<qst_Marks>10</qst_Marks> 
<qst_company_code>1</qst_company_code> 
<user_code>1</user_code> 

+0

XML将数据保存在树中。 SQLite将数据保存在表中。在树和表之间转换有很多方法;我不能帮你选择最好的方式,因为我不知道数据是什么样子或者你在做什么。你将不得不提供更多的信息。 – 2012-02-21 05:20:47

+0

感谢迈克我提供的XML数据结构 – naleshmadur 2012-02-21 05:59:16

回答

3

一种选择是将其存储为一个字符串,如果数据不能太大,否则就闯入映射到SQLite和重建它在加载模式。

1

如果您的XML数据很大,我宁愿将数据交换类型更改为json。 XML解析然后插入是一个非常昂贵的操作,并且非常耗时。

您将在XML解析和插入时遇到的一些问题。

a。 XML解析是内存密集型的,所以你的堆大小会增长,你需要留意这个,因为这可能会导致崩溃。 b。 SQLite DB中的插入每个元组(行)需要大约100ms,因此您可以计算在数千行数据中需要抽取的时间。

如果你的数据不是太大,不要打扰使用SQLite。

相关问题