XML : Why is the XML node's parent node being changed?

I have searched on here and Google for an answer to this but I cannot find a thing, apologies if this is something simple.

I have the below code:

          private XmlNode loadXMLNode(string configPath, string loggingPath)      {          configFile.Load(configPath);          XmlNode logging = configFile.DocumentElement.SelectSingleNode(loggingPath);          return logging;      }        public string testXMLNodeValue(string configPath, string loggingPath)      {          XmlNode logging = loadXMLNode(configPath, loggingPath);          string value = logging.Attributes["value"].Value;          return value;      }        public void setXMLNodeValue(string configPath, string loggingPath, string newValue)      {          XmlNode logging = loadXMLNode(configPath, loggingPath);          logging.Attributes["value"].Value = newValue;          MessageBox.Show(logging.Attributes["value"].Value);          configFile.Save("C:\\inetpub\\CiresonPortal\\bin\\Cireson.CacheBuilder.Service.exe.config");      }    

Which does correctly load the XML file and does modify the value in the targeted node. However it also changes the name of the parent node and I have no idea why.

(If you're wondering why the final path is hard coded it is because it was not saving the file at all when using the path from the configuration file, but that is a question for another thread.)

It should look like this:

      <logger name="Logger">    <!-- LEVELS: ALL, DEBUG, INFO, WARN, ERROR, FATAL-->    <!-- Suggested for debugging: INFO -->    <!-- Suggested for production: WARN -->    <level value="ERROR" />    

However once the above code runs it looks like this:

      <root>    <level value="ERROR" />    

Any help would be very much appreciated as I am still teaching myself c# (coming from a PowerShell background).

Thank you.

No comments:

Post a Comment