Question : reading an xml file in c#

Hello all, below I have an xml file that I made that is just appliction settings for a program I am writing in C#. I need to know in code how to read this XML file.
What I want to do is read the values and assign them to a variable that is kept in memory for as long as the application is loaded. When the application is closed, I will write a routine that will set those values to "Nothing". Here is the xml file below. Thanks in advance.

Code Snippet:
1:
2:
3:
4:
5:

  
  
  

Answer : reading an xml file in c#

Very simple example below. XmlTextReader is an option, but the XmlDocument class will suffice since its only a small file an I doubt optimisation is your first priority at this point.

However for this sort of thing you would be better to use the built-in configuration file features of teh framework, that is after all what they are there for:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("C:\\test.xml");

            ip = doc.SelectSingleNode("Configuration/ServerIP").Attributes["value"].InnerText;
            port = doc.SelectSingleNode("Configuration/CommPort").Attributes["value"].InnerText;
            logging = doc.SelectSingleNode("Configuration/Logging").Attributes["value"].InnerText;

            Console.WriteLine("{0}:{1}:{2}", ip, port, logging);
            Console.ReadLine();
        }

        private static string ip;
        private static string port;
        private static string logging;
Random Solutions  
 
programming4us programming4us