Read data from XML and store into Data Set Using C#

I am using XML file as config file in my automation tool which I have developed to store all the inputs/settings/run time config value etc etc. Because it easy for manual guys also to just open XML file in Notepad and alter the setting based on their requirement and it’s easy to maintain also.

Below is the code which I am using to Read data from XML file and store in to Data set for further use.

//Local vaible to get xml path

string xmlPath=”Inputs.xml”;

//Read all the value to the xml read command

System.IO.FileStream fsReadXml = new System.IO.FileStream(xmlPath,

System.IO.FileMode.Open);

//Declare a dataset to hold all the XML value

DataSet ds = new DataSet();

try

{

//Read the value from XML reader to the dataset

ds.ReadXml(fsReadXml);

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

finally

{

//Close the reader.

fsReadXml.Close();

}

//your dataset (ds) would be having all the data stored from XML file.

Thanks,

Md.Jawed

2 thoughts on “Read data from XML and store into Data Set Using C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s