我打算使用XML来存储我正在编写的Java DVD数据库应用程序的数据。 我知道“数据库”这个词在标题中就是正确的,但是XML看起来更容易移植,易于人工阅读,并且(我在设想之前假设)更容易实现。
解析XML似乎是世界上最简单的事情......即使创建一个新的XML文件也不是什么麻烦,但是改变记录,插入或删除它们,我只能通过创建一个新的XML文件来实现。
我错过了什么吗? 或者是我错过了我应该切换到数据库格式(但有一些我没有听说过的美妙的数据库格式,这是完全可移植的,用户不需要单独安装一些东西:))
I was planning to use XML to store the data for a Java DVD database application I'm writing. I know that the word "database" is right there in the title, but XML just seemed so much more portable, was human readable and (I assumed before looking into it) simpler to implement.
Parsing XML seems to be the easiest thing in the world... even creating a new XML file isn't much trouble, but changing records, inserting them or deleting them, I can only see to do by creating a fresh XML file.
Am I missing something? Or is the thing that I'm missing that I should switch over to a database format (but there's some wonderful database format I've not heard of, that's totally portable and users won't need to install something separate to use :) )
最满意答案
使用文件作为数据库的最流行的方式可能是用sqlite http://www.sqlite.org/ ,这就是我会用如果我解决你的问题(这几乎是一个标准的SQL数据库,但只使用一个文件作为存储)。 另一个纯java选项是apache derby http://db.apache.org/derby/
然而,纯xml数据库确实存在(10年前相当流行 - 它们时代的“nosql”) - 相关标准是xpath http://en.wikipedia.org/wiki/XPath和xquery http:// en.wikipedia.org/wiki/Xquery 。 我没有使用它,但它似乎像basex http://basex.org/open-source/是一个开源的实现,你可以使用(它声称提供ACID保证 - http:// basex。 org / products / )。
如果你更熟悉xml而不是sql,那么对于使用xml数据库来做小型项目并不会有什么大的伤害。 只是构建你的代码,以便大部分程序不关心存储是什么(即通过提供一个中立的接口)。 那么如果xml不能解决问题,你可以通过重新实现这个接口并将剩下的程序单独留下来切换到sql(如果它确实有效,请在这里回复 - 这会很有趣)。
the most popular way to use a file as a database is probably with sqlite http://www.sqlite.org/ and that's what i would use if i were solving your problem (it's pretty much a standard SQL database, but uses just one file as storage). another, pure-java option is apache derby http://db.apache.org/derby/
however, pure xml databases do exist (and were quite fashionable about 10 years ago - the "nosql" of their time) - the associated standards are xpath http://en.wikipedia.org/wiki/XPath and xquery http://en.wikipedia.org/wiki/Xquery . i haven't used it, but it seems like basex http://basex.org/open-source/ is an open-source implementation that you could use (and it does claim to provide ACID guarantees - http://basex.org/products/ ).
if you're more familiar with xml than sql i don't see any great harm in using an xml database for a small project. just structure your code so that most of the program doesn't care what the storage is (ie by providing a neutral interface). then if xml doesn't work out you can switch to sql by re-implementing just that interface and leaving the rest of your program alone (and if it does work, post back here saying so - it would be interesting to know).
更多推荐
发布评论