Getting specifiec node value from XML file using C#

        Getting Node values from the XML file using C# is pretty simple, Read the XML file as shown below, then read the node and child nodes that you have placed the values, Here I am getting the Connection string from the XML file.



XML

<BATCHEXTRACT>
  <DBDETAILS>
<SQLCONNECTIONSTRING>server=dev.com.lpg;database=Oscar;uid=s_os;pwd=l@cto</SQLCONNECTIONSTRING>
    <CONNECTIONTIMEOUT>6000</CONNECTIONTIMEOUT>
  </DBDETAILS>
</BATCHEXTRACT>

C#


using System;
using System.Collections.Generic;
using System.Xml;

namespace COSTING_PURGE_BATCH
{
  public class Common
  {
    public string GetSQLConnectionString()
    {
      XmlDocument Docs = new XmlDocument();
      try
      {
        Docs.Load("CPB_Constants.xml");//file in Debug Folder
        string ConString = Docs.SelectSingleNode("//BATCHEXTRACT/DBDETAILS/SQLCONNECTIONSTRING").InnerText.ToString();
         return ConString;
      }
      catch (Exception ex)
      {
          throw ex;
      }
    }
  }
}