<Setting1>
<SubSetting1>Test1</SubSetting1>
<SubSetting2>Test2</SubSetting2>
</Setting1>
<Setting2>
<SubSetting1>Test3</SubSetting1>
<SubSetting2>Test4</SubSetting2>
</Setting2>
这只是一个参考 xml 文档的小例子。我正在尝试学习如何在不覆盖 xml 标记的情况下附加现有的 xml 文档。我的实际 xml 文档有更多节点(大约 40 个),我将所有新值(代替 Test1、Test2、..etc)放入一个列表中。以正确的顺序,所以我正在考虑使用 For 循环来写入值。
像这样的东西?
Public Sub example (ListofSettings As List(of String))
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory)
Dim myNodes, myChildren As XmlNodeList
settingsFile.Load(SETTINGS_FILE_PATH)
myNodes = settingsFile.GetElementsByTagName("Settings1")
For i as Integer = 0 to ListofSettings.count
For Each n As XmlNode In myNodes
If n.Name = "Settings1" Then
myChildren = n.ChildNodes
For Each n1 As XmlNode In myChildren
Select Case n1.Name
Case "SubSetting1"
writer.WriteElementString(**DONT WANT TO CHANGE TAG NAME**, ListofSettings.Item(i))
End Select
Next
End if
Next