在VB.net中编辑XML文件 [英] Editing XML file in VB.net
问题描述
我在开发中是零(或几乎),但我正在尝试使用XML文件进行简单的应用程序进行某些设置。我有一个可能很简单的问题,但我发现网上的所有信息都没有帮助我找到一个可行的解决方案。
我在VB中使用VisualStudio2013 .net和我正在尝试更新结构化的xml文件中的值,如下所示:
Hi,
I'm a zero (or almost) in development but I'm trying to do simple application using XML file for some settings. I have a probably simple question but all the information I found an the web didn't helped me to find a working solution.
I'm working with VisualStudio2013 in VB.net and I'm trying to update values in the xml file strucutred like this :
<config>
<path>
<path1>c:\test</path1>
<path2>c:\windows</path2>
<path3>c:\users</path3>
<path4>c:\temp</path4>
</path>
<option>
<option1>something</option1>
<option2>anything</option2>
</option>
</config>
你可以想象,我正在尝试修改一些路径和选项价值。
如果你有一个解决方案,那就太棒了......
谢谢你,
Vince。
As you can imagine, I'm trying to modify some path and option value.
If you have a solution for me it would be awsome...
Thank you,
Vince.
推荐答案
最简单的方法是使用 DataSet [ ^ ],它提供了一种方法 read [ ^ ]和写 [ ^ ] XML。
在这种情况下,你需要添加两个 DataTables [ ^ ]到DataSet,一个用于路径
节点,一个用于选项
节点。每个DataTable应包含对应于节点结构的列(分别为:path1
到path4
和option1
到option2
)。
还有其他几种方法(即: XmlDocument [ ^ ]),但我建议你把注意力转移到 XML序列化和反序列化 [ ^ ],它可以帮助您将对象转换为XML格式,反之亦然。使用 SearchBox [ ^ ]在此站点的右上角搜索有关XML序列化和反序列化的文章。
The simplest way is to use DataSet[^], which provide a way to read[^] and write[^] XML.
In this case, you need to add two DataTables[^] to the DataSet, one forpath
node and one foroption
node. Each DataTable should contains columns which correspond to node structure (respectively:path1
topath4
andoption1
tooption2
).
There is several other ways to to that (i.e.: XmlDocument[^]), but i suggest to move your attention on XML serialization and deserialization[^], which can help you to convert an object into an XML form and vice versa. Use SearchBox[^] on the right-top corner of this site to search for articles about XML serialization and deserialization.
这篇关于在VB.net中编辑XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!