VB.NET: Updating XML Node Changes XML Formatting

onuprobesh

New Member
I am trying to update an XML document and replace the contents of a single node, however, after I save the XML file, my formatting goes all skew.This is my code:\[code\]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 = NothingEnd Sub\[/code\]My original XML File (before I update the node) looks like this:\[code\]<?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>\[/code\]However, once I save the XML file my formatting looks like this:\[code\]<?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>\[/code\]Not sure what I'm doing wrong, but I can't seem to find any info on the web about this issue. Wondering if someone could help my please. Any help would be appreciated.Thanks
 
Top