I am going to show you a code demo which can be used to create a simple XMl file and later can be used to store the data.The code to create an XML file would be as follows-
Code:
using System;
using System.Xml;
namespace PavelTsekov
{
class MainClass
{
XmlDocument xmldcs;
XmlNode xmlnd;
XmlElement xmlelement;
XmlElement xmlelement2;
XmlText xmltxt;
static void Main(string[] args)
{
MainClass aplctn =new MainClass();
}
public MainClass()
{
xmldcs=new XmlDocument();
xmlnd=xmldcs.CreateNode(XmlNodeType.XmlDeclaration,"","");
xmldcs.AppendChild(xmlnd);
xmlelement=xmldcs.CreateElement("","ROOT","");
xmltxt=xmldcs.CreateTextNode("This is the text of the root element");
xmlelement.AppendChild(xmltxt);
xmldcs.AppendChild(xmlelement);
xmlelement2=xmldcs.CreateElement("","SampleElement","");
xmltxt=xmldcs.CreateTextNode("The text of the sample element");
xmlelement2.AppendChild(xmltxt);
xmldcs.ChildNodes.Item(1).AppendChild(xmlelement2);
{
xmldcs.Save("c:\my_data_file.xml");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}
Bookmarks