是否可以将用户数据存储在 XML 文件中?
我有一个应用程序正在被一些用户(<12 个用户)使用。记录少于 2000 条,因此我决定使用 XML 文件并将该文件存储在 \company\product\p.xml 下。
这可以吗?还是我在没有意识到的情况下违反了一些设计准则?
EnvironmentL .net/c#/winforms
更新:在任何给定时间只有 1 个用户、1 个线程会读取或更新。
I have an app that is being used by a few users (< 12 users). There are less than 2000 records so I decided to use an XML file and store the file under \company\product\p.xml.
Is this okay or am I breaking some design guidelines without realizing it?
EnvironmentL .net/c#/winforms
Update: Only 1 user, 1 thread will be reading or updating at any given time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于文件,您需要确保不超过一个线程/进程或其他工作单元同时写入该文件,否则存在损坏的风险。
如果您需要多个并发写入,SQLite 可能是一个很好的解决方案。
With a file you need to make sure that no more than one threads/processes or other units of work will be writing to it concurrently or risk corruption.
SQLite might be a good solution if you require multiple concurrent writes.
如果没有太多记录需要处理,那么使用 XML 文件就可以了,它也可能是可移植的。
If there are not much records to handle then its ok to use XML file, it might turn out to be portable as well.
紧凑的 sql 会更好地完成这项工作。甚至只使用 odbc 和 access 数据库。 xml 文件并不是真正用作数据库。
Compact sql would do the job alot better. Even just use odbc and an access database. xml files are not really ment to be used as a database.
值得注意的是,XML 文件中的信息存在一些安全隐患,这些文件本质上是明文,可以由任何文本编辑器读取。任何违反隐私法的内容(例如社会安全号码)都不应该存储在 XML 文件中。密码不应存储在未加密的 XML 文件中。
这听起来很明显,但我知道在我曾经工作过的一份工作中至少有一个 ASP.NET 应用程序的设计包括模拟帐户的明文密码......愚蠢。
It's worth noting that there are some security implications for information that goes into XML files which are essentially clear text, and can be read by any text editor. Anything that violates privacy laws, such as social security numbers, should not be stored in an XML file. Passwords should not be stored in an XML file unencrypted.
This sounds obvious, but I know of at least one ASP.NET application at a job where I used to work where the design included a clear text password for an impersonation account...Stupid.
最好的选择是在数据存储和应用程序之间使用某种形式的抽象(例如 ORM)。您不必将整个 MVC 堆栈引入代码中,而是尝试自己组合一些适合您需求的东西。然后你可以将你的后端从 XML 文件切换到其他人在这里建议的内容
Your best bet is to use some form of abstraction between your data storage and your application ( like an ORM ). You don't have to bring in an entire MVC stack into you code, but try to throw something together yourself that fits your needs. Then you can switch your backend from an XML file to a what other people have suggested here