XML 到 LINQ 问题

发布于 2024-08-09 15:38:33 字数 993 浏览 3 评论 0原文

在我开始之前,先简单概述一下我想要实现的目标,然后我们将深入讨论具体细节。目前,我正在开发一个应用程序,它将监视用户注册表以了解与用户首选项相关的特定键的更改。目前正在使用强制配置文件(不是我的选择),无论如何,整个想法是将更改记录到一个位置,以便下次登录时可以将更改写回用户注册表。

目前,我有系统监视注册表更改并触发事件,返回已更改的键、值名称和值。我将这些输入到列表中以创建包含所有数据的单个字符串,然后经常将该列表写入文本文件。现在一切都很好,但我需要更改数据的保存方式,因为将字符串再次分解为键、值名称和值,以便写回注册表需要太多开销,而且还存在将字符串分解为唯一可识别的问题时尚。

所以有人建议我看看 XML,我以前没有使用过它,我已经开始研究它,它看起来很简单,我之前也使用过 LINQ 来连接到嵌入式数据库。我目前正在努力解决的是 LINQ 如何从 XML 检索和操作内存中的数据,因为我不想不断访问 XML 文件,因为需要保持应用程序的速度尽可能。目前,注册表中的所有更改都会缓存到列表(字符串)中,然后每分钟左右写入文本文件。

目前我所拥有的是系统返回不同字符串中的键、值名称和值,将它们汇聚成一个列表(字符串)值,而我需要的是表示键的表或等效项,其中包含多个值名称,每个值名称包含一个值,最后是一个类型(这将是一个代表注册表值类型的数字,REG SZ、REG BINARY 等)。在 XML 文件和程序本身中。

另外,我不太明白的是,与数据库不同的是,在程序首次运行之前,表和架构不会存在,因为它将创建一个新的 XML 文件,而不是已经存在的文件。这是因为信息被写回用户的个人驱动器,因此必须在首次在用户计算机上运行时创建它。

我已经尝试了一些链接和教程等,但还没有点击任何内容,因此,如果您有一个示例或者可以向我更好地解释一下,我将不胜感激。

我想补充的最后一点是,我当前在程序中存储数据的想法是创建一个值列表,嵌入到值名称列表中,以及嵌入到键列表中的值名称列表。听起来不错吗?

现在我知道这很长,而且有点到处都是,所以如果有人可以提供帮助,我们将不胜感激,或者如果您需要进一步的澄清信息,请告诉我,我会尽力而为。

谢谢

Just before I begin heres a small overview of what I'm trying to achieve and then we'll get down to the gory details. At present I'm developing an application which will monitor a users registry for changes to specific keys which relate to user preferences. Were currently using mandatory profiles (not my choice), anyway the whole idea is to record the changes to a location where they can be writen back to a users registry next time they log on.

At the moment I have the system monitoring registry changes and firing events returning the key, value name and value that have changed. I was entering these into a list to create a single string containing all the data, then writing that list to a text file every so often. Now this has all been fine but I need to change the way data's held as breaking the strings down into key, value name and value again for the write back to registry requires too much overhead and theres also problems breaking the strings up in a uniquely identifiable fashion.

So it was suggested to me to look at XML, which I haven't used before and I've begun investigating it and it all looks simple enough, I've also used LINQ before to connect to embedded databases. What I'm currently struggling to get my head around is how LINQ is able to retrieve and manipulate the data in memory from XML, as I don't want to be constantly accessing the XML file due to a need to keep the application as quick as possible. At present all changes in the registry are cached into a List(String) then written to a text file every minute or so.

At the moment what I have is the system returning the key, value name and value in different strings, converging these into a single List(String) value, where as what I'm going to need is table or equivalent representing a key, which contains multiple value names with each value name containing a single value and finally a type (this wil be a number representing what kind of registry value this is, REG SZ, REG BINARY etc). Both in the XML file and the program it self.

Also what I don't quite get is unlike a database the tables and there schemas won't exist until the program first runs as it will create a new XML file rather than it already existing. This is due to the information being writen back to the users personal drive, so it has to be created when it first runs on the users machine.

I've tried a few links and tutorials etc but nothing has clicked just yet, so if you have an example or could maybe explain it to me a little better it would be appreciated.

Just one final bit I want to add is that my current idea for storing the data in program is to create a List of values, embedded in a List of value names and a list of value names embedded in a list of keys. Does that sound ok?

Now I know this is long, and kind of all over the place, so if someone could help it would be appreciated or if you require further information of clarification please let me know and I'll try my best.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小梨窩很甜 2024-08-16 15:38:33

据我了解,你只是想错了方向。您的应用程序不想在内存中操作 XML。您只想使用内存中的某些数据结构,并希望有一种简单的方法将其存储到光盘并读回?如果我理解正确的话:

不要关心 LINQ for XML。只需看一下 XML 序列化基础架构中的构建即可。然后构建适合您的应用程序需求的内部数据结构,并使用 XmlSerializer 将其写入光盘并读回。无需手动接触任何 XML!

From what I understand, you are just thinking in the wrong direction. Your application does not want to manipulate XML in memory. You just want to work with some data structure in memory and would like to have an easy way to store it to disc and to read it back? If I understand that right:

Don't care about LINQ for XML. Just have a look at the build in XML serialization infrastructure. Then build an internal data structure which fits your applications needs and use an XmlSerializer to write it to disc and to read it back. No need to touch any XML by hand!

岁月无声 2024-08-16 15:38:33

根据您的描述,在这里使用 XML 似乎是个好主意。

至于访问内存中的 XML dta,我发现 MSDN 文档非常有帮助:
http://msdn.microsoft.com/en-us/library/bb387098。 aspx

基本思想是,LINQ-to-XML 只是 LINQ-to-Objects,使用表示 XML 元素的对象。

恐怕我不太明白你的第二个问题。

From what you describe it does seem like a good idea to use XML here.

As for accessing the XML dta in memory, I found the MSDN documentation quite helpful:
http://msdn.microsoft.com/en-us/library/bb387098.aspx

The basic idea is, LINQ-to-XML is just LINQ-to-Objects, working with objects that represent the XML elements.

I'm afraid I don't quite get your second question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文