XmlDocument doc = new XmlDocument();
//Create Root Element
XmlElement root = doc.CreateElement("Datasource");
//Create Var Tag Node
XmlElement var = doc.CreateElement("var");
//Apply Host Name Attribute to the var element
var.SetAttribute("name", "Host");
// create innertext element for var
XmlElement str = doc.CreateElement("string");
str.InnerText = "127.0.0.1";
//add inntertext element to the var node
var.AppendChild(str);
//add var node in root node
root.AppendChild(var);
var = doc.CreateElement("var");
var.SetAttribute("name", "Database");
str = doc.CreateElement("string");
str.InnerText = "TestDB";
var.AppendChild(str);
root.AppendChild(var);
var = doc.CreateElement("var");
var.SetAttribute("name", "Username");
str = doc.CreateElement("string");
str.InnerText = "Root";
var.AppendChild(str);
root.AppendChild(var);
var = doc.CreateElement("var");
var.SetAttribute("name", "Password");
str = doc.CreateElement("string");
str.InnerText = "Root123";
var.AppendChild(str);
root.AppendChild(var);
doc.AppendChild(root);
//Create Xml File To Application Start up Path Folder
doc.Save(Application.StartupPath + "_datasource.xml");
//Create Root Element
XmlElement root = doc.CreateElement("Datasource");
//Create Var Tag Node
XmlElement var = doc.CreateElement("var");
//Apply Host Name Attribute to the var element
var.SetAttribute("name", "Host");
// create innertext element for var
XmlElement str = doc.CreateElement("string");
str.InnerText = "127.0.0.1";
//add inntertext element to the var node
var.AppendChild(str);
//add var node in root node
root.AppendChild(var);
var = doc.CreateElement("var");
var.SetAttribute("name", "Database");
str = doc.CreateElement("string");
str.InnerText = "TestDB";
var.AppendChild(str);
root.AppendChild(var);
var = doc.CreateElement("var");
var.SetAttribute("name", "Username");
str = doc.CreateElement("string");
str.InnerText = "Root";
var.AppendChild(str);
root.AppendChild(var);
var = doc.CreateElement("var");
var.SetAttribute("name", "Password");
str = doc.CreateElement("string");
str.InnerText = "Root123";
var.AppendChild(str);
root.AppendChild(var);
doc.AppendChild(root);
//Create Xml File To Application Start up Path Folder
doc.Save(Application.StartupPath + "_datasource.xml");