我正在尝试更新 XML 文档并替换单个节点的内容,但是,在我保存 XML 文件后,我的格式完全偏斜。
这是我的代码:
Public Sub UpdateSettingsXML(ByRef ElementName As String, ByRef ElementValue As String)
Dim MyXML As New XmlDocument()
Dim MyXMLNode As XmlNode
MyXML.Load(SettingsXMLFile)
MyXMLNode = MyXML.SelectSingleNode("//Data/Settings/" & ElementName)
If Not MyXMLNode Is Nothing Then
MyXMLNode.InnerText = ElementValue.ToString
MyXML.Save(SettingsXMLFile)
End If
MyXMLNode = Nothing
MyXML = Nothing
End Sub
我的原始 XML 文件(在更新节点之前)如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Data>
<Settings>
<DropBoxLocation></DropBoxLocation>
<ServerName></ServerName>
<DatabaseName></DatabaseName>
<Username></Username>
<Password></Password>
<OnlineFilename></OnlineFilename>
<OfflineFilename></OfflineFilename>
<EftposFilename></EftposFilename>
<BankFilename></BankFilename>
<POSFilename></POSFilename>
<ProcessesFilename></ProcessesFilename>
<FileReadDelay></FileReadDelay>
</Settings>
</Data>
但是,一旦我保存 XML 文件,我的格式将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Data>
<Settings>
<DropBoxLocation>C:\Dropbox</DropBoxLocation>
<ServerName>
</ServerName>
<DatabaseName>
</DatabaseName>
<Username>
</Username>
<Password>
</Password>
<OnlineFilename>
</OnlineFilename>
<OfflineFilename>
</OfflineFilename>
<EftposFilename>
</EftposFilename>
<BankFilename>
</BankFilename>
<POSFilename>
</POSFilename>
<ProcessesFilename>
</ProcessesFilename>
<FileReadDelay>
</FileReadDelay>
</Settings>
</Data>
不知道我做错了什么,但我似乎无法在网上找到有关此问题的任何信息。想知道是否有人可以帮助我。任何帮助,将不胜感激。
谢谢