程序代码:
Private Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button7.Click
'测试用 获取A的value,和B的value,并且修改保存
Dim cpath As String = "E:\vbnet.prj\ModifyFileZillaXml\ModifyFileZillaXml\bin\Debug\sets.xml"
Dim xd As New Xml.XmlDocument
Dim aValue As String = "", bValue As String = "", cSettingName As String
xd.Load(cpath)
For Each nodeSets As Xml.XmlNode In xd.SelectSingleNode("configuration").SelectSingleNode("appsettings").SelectSingleNode("Bassettings")
cSettingName = nodeSets.Attributes("name").Value
Select Case cSettingName
Case "A"
aValue = nodeSets.InnerText
nodeSets.ChildNodes(0).ChildNodes(0).Value = "99"
Case "B"
bValue = nodeSets.InnerText
nodeSets.ChildNodes(0).ChildNodes(0).Value = "999"
End Select
Next
'写到硬盘,释放内存。
Dim tr As Xml.XmlTextWriter = New Xml.XmlTextWriter(cpath, Nothing) '写XML文件。
tr.Formatting = Xml.Formatting.Indented
xd.WriteContentTo(tr)
tr.Close() '释放内存。
Debug.Print("setting A.OldValue=" & aValue & ",修改后的值:99")
Debug.Print("setting B.OldValue=" & bValue & ",修改后的值:999")
End Sub
运行结果:
setting A.OldValue=0,修改后的值:99
setting B.OldValue=10000,修改后的值:999