在Visual Basic中编辑XML文件中的值 [英] Editing values in an XML file in Visual Basic
本文介绍了在Visual Basic中编辑XML文件中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!
我正在尝试编写一个小程序,它会更改xml文件中的值。我想编辑两个标签之间的文字。
Hi!
I'm trying to write a little program, that changes a value in an xml file. I want to edit the text between two tags.
<option>text to change</option>
你能帮忙吗?
Could you please help?
推荐答案
从这里开始: Visual Basic中的XML [ ^ 并按照左边的链接。
至少有几种方法:
如何使用Visual Basic .NET从文件中读取XML [ ^ ]
如何:在Visual Basic .NET中序列化和反序列化XML [ ^ ]
如何:使用XmlReader解析XML [ ^ ]
Visual Basic中LINQ to XML概述 [ ^ ]
示例代码:如何使用.NET Framework SDK中的XmlDocument类修改和保存XML [ ^ ]
假设你的xml看起来像:
Start here: XML in Visual Basic[^] and follow the links on the left.
There is at least few ways:
How to read XML from a file by using Visual Basic .NET [^]
HOW TO: Serialize and Deserialize XML in Visual Basic .NET[^]
How to: Parse XML with XmlReader[^]
Overview of LINQ to XML in Visual Basic[^]
Sample code: How To Modify and Save XML with the XmlDocument Class in the .NET Framework SDK[^]
Let's say your xml looks like:
<options>
<option>initial text</option>
</options>
代码如下:
The code could looks like:
Dim xdoc As XDocument = XDocument.Load("D:\opt.xml")
Dim ele = xdoc.Elements("options").Elements("option")
ele.Value = "optional text"
xdoc.Save("D:\opt.xml")
结果:
Result:
<options>
<option>optional text</option>
</options>
这篇关于在Visual Basic中编辑XML文件中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文