存储设置:XML与SQLite的? [英] Storing settings: XML vs. SQLite?

查看:618
本文介绍了存储设置:XML与SQLite的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个IRC客户端,我一直在试图找出存储服务器设置的好方法。基本上网络的大名单和他们的服务器,因为大多数IRC客户端有。

I am currently writing an IRC client and I've been trying to figure out a good way to store the server settings. Basically a big list of networks and their servers as most IRC clients have.

我已经决定使用SQLite的,但后来我想使列表在线免费提供XML格式(也许是最终的),对于其他IRC应用程序使用。所以,现在我可能只是在本地存储在相同的格式设置。

I had decided on using SQLite but then I wanted to make the list freely available online in XML format (and perhaps definitive), for other IRC apps to use. So now I may just store the settings locally in the same format.

我有一个ADO.NET或XML的,所以我不知道他们将如何在这样的情况比较经验非常少。

I have very little experience with either ADO.NET or XML so I'm not sure how they would compare in a situation like this.

是一个更容易编程的工作吗?是更快?有没有关系呢?

Is one easier to work with programmatically? Is one faster? Does it matter?

推荐答案

这比你意识到一个模糊的问题。 设置可以包括非常多的东西。

It's a vaguer question than you realize. "Settings" can encompass an awful lot of things.

还有处理配置文件中的应用程序设置一个很好的.NET架构。这些,一般都暴露在你的程序作为对象的全局设置属性;类中的 System.Configuration 命名空间照顾读书,坚持他们,并且有内置到Visual Studio中的工具自动生成的code处理这些问题。其中这些基础设施支持的数据类型是 StringCollection ,所以你可以用它来存储服务器列表。

There's a good .NET infrastructure for handling application settings in configuration files. These, generally, are exposed to your program as properties of a global Settings object; the classes in the System.Configuration namespace take care of reading and persisting them, and there are tools built into Visual Studio to auto-generate the code for dealing with them. One of the data types that this infrastructure supports is StringCollection, so you could use that to store a list of servers.

但对于服务器的大名单,这不会是我的第一选择,因为有两个原因。我期望,在列表中的元素实际上是元组(如主机名,端口的描述),不是简单的字符串,在这种情况下,你最终不得不格式化和分析数据,以得到它变成一个 StringCollection ,那就是通常,你应该做别的事情的一个标志。此外,应用程序设置为只读(在Vista下,至少),虽然你可以给一个设定的用户范围,使之持久化,导致你失望,你可能要承诺之前,了解的途径。

But for a large list of servers, this wouldn't be my first choice, for a couple of reasons. I'd expect that the elements in your list are actually tuples (e.g. host name, port, description), not simple strings, in which case you'll end up having to format and parse the data to get it into a StringCollection, and that is generally a sign that you should be doing something else. Also, application settings are read-only (under Vista, at least), and while you can give a setting user scope to make it persistable, that leads you down a path that you probably want to understand before committing to.

因此​​,另一件事我会考虑:你的服务器的列表只是一个列表,或者你有一个内部对象模型重新presenting呢?在后一种情况下,我可能会考虑使用XML序列来存储和检索的对象。 (我唯一会保持应用程序的配置文件将是路径序列化对象的文件。)我会做这个,因为序列化和反序列化简单对象转换为XML是很容易;你不必与设计和测试适当的序列化格式,因为这些工具为你做它担心。

So, another thing I'd consider: Is your list of servers simply a list, or do you have an internal object model representing it? In the latter case, I might consider using XML serialization to store and retrieve the objects. (The only thing I'd keep in the application configuration file would be the path to the serialized object file.) I'd do this because serializing and deserializing simple objects into XML is really easy; you don't have to be concerned with designing and testing a proper serialization format because the tools do it for you.

主要的原因我看使用的数据库是,如果我的程序执行了一堆的操作,其结果必须是原子耐用,或如果由于某种原因,我不希望我所有的数据在内存中一次。如果每个时间x发生,我想它的永久记录,这是导致我在使用数据库的方向。你不希望使用XML序列化类似的东西,一般,因为如果你保存您的所有对象的单个物理文件,你不能切实序列化只是一个对象。 (虽然它肯定不是疯了,系列化你的整个对象模型来保存一个改变事实上,这正是我公司的产品呢,它指向另一个环境中,我不会使用一个数据库:如果数据的模式是经常变化。)

The primary reason I look at using a database is if my program performs a bunch of operations whose results need to be atomic and durable, or if for some reason I don't want all of my data in memory at once. If every time X happens, I want a permanent record of it, that's leading me in the direction of using a database. You don't want to use XML serialization for something like that, generally, because you can't realistically serialize just one object if you're saving all of your objects to a single physical file. (Though it's certainly not crazy to simply serialize your whole object model to save one change. In fact, that's exactly what my company's product does, and it points to another circumstance in which I wouldn't use a database: if the data's schema is changing frequently.)

这篇关于存储设置:XML与SQLite的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆