Writing XML File in Dot Net

Puneet20884
Posted by Puneet20884 under C# category on | Views : 2702
The COde illustrate itself the usage, its a simple code.
Here it goes :

Special Directives for it :

using System.IO;
using System.Xml;
using System.Text;
----------------------

XmlTextWriter Writer = new XmlTextWriter(ConfigurationManager.AppSettings["GreetingsSettingFile"].ToString(), System.Text.Encoding.ASCII);
Writer.Formatting = Formatting.Indented;
Writer.WriteStartDocument(true);
Writer.WriteComment("Greetings Setting");
Writer.WriteStartElement("Settings");
Writer.WriteAttributeString("DateModified", DateTime.Now.ToString());

Writer.WriteStartElement("Greetings");

Writer.WriteStartElement("Greeting");
Writer.WriteElementString("ID1", strIdUpper1);
Writer.WriteElementString("Name1",strNameUpper1 );
Writer.WriteEndElement();

Writer.WriteStartElement("Greeting");
Writer.WriteElementString("ID1", strIdUpper1);
Writer.WriteElementString("Name1", strNameUpper1);
Writer.WriteEndElement();

Writer.WriteStartElement("Greeting");
Writer.WriteElementString("ID1", strIdUpper1);
Writer.WriteElementString("Name1", strNameUpper1);
Writer.WriteEndElement();

Writer.WriteStartElement("Greeting");
Writer.WriteElementString("ID1", strIdUpper1);
Writer.WriteElementString("Name1", strNameUpper1);
Writer.WriteEndElement();

Writer.WriteEndElement(); // Item End Tag

Writer.WriteEndDocument();

Writer.Flush();

Writer.Close();

Comments or Responses

Login to post response