【学习】XML VS SQLite

来源:互联网 发布:化妆品数据分析 编辑:程序博客网 时间:2024/05/22 19:29

Advantages of sqlite over xml:

  • everything in one file,
  • performance loss is lower than XML as cache gets bigger,
  • you can keep feed metadata separate from cache itself (other table), but accessible in the same way,
  • SQL is probably easier to work with than XPath for most people.

Disadvantages of sqlite:

  • can be problematic with multiple processes accessing same database (probably not your case),
  • you should know at least basic SQL. Unless there will be hundreds of thousands of items in cache, I don't think you will need to optimize it much,
  • maybe in some way it can be more dangerous from security standpoint (SQL injection). On the other hand, you are not coding web app, so this should not happen.


Here is a summary

  1. For tree data, XML is much easier to query and modify using XPATH.

  2. For small datasets (less than 10M), XML blew away sqlite in performance.

  3. For large datasets (greater than 10M-100M), XML load time and memory usage became a big problem, to the point that some computers become unusable.

  4. We couldn't get any opensource xml database to fix the problems associated with large datasets.

  5. SQLITE doesn't have the memory problems of XML dom, but it is generally slower in processing the data (it is on the hard drive, not in memory). (note- sqlite tables can be stored in memory, perhaps this would make it as fast.... We didn't try this because we wanted to get the data out of memory.)

  6. Storing and querying tree data in a table is not enjoyable. However, managing transactions and indexing partially makes up for it.


XML is best used as an interchange format(注:个人觉得针对网络传输,XML或JSON更适合) when you need to move data from your application to somewhere else or share information between applications. A database should be the preferred method of storage for almost any size application.

参考链接:
http://stackoverflow.com/questions/77726/xml-or-sqlite-when-to-drop-xml-for-a-database
http://answers.oreilly.com/topic/1959-when-to-use-sqlite-instead-of-core-data-on-the-iphone/
http://en.wikipedia.org/wiki/SQLite(有中文介绍)