try
{
stringfilename = "c:\\firstXML.xml";
//assigning file name of desiredfile we want to create.
XmlDocumentxmlDoc = newXmlDocument();
//creating new XML document
XmlTextWriter xmlWriter= new XmlTextWriter(filename, System.Text.Encoding.UTF8);
//creating XmlTestWriter, andpassing file name and encoding type as argument
xmlWriter.Formatting = Formatting.Indented;
//setting XmlWriter formating tobe indented
xmlWriter.WriteProcessingInstruction("xml", "version='1.0'encoding='UTF-8'");
//writing version and encodingtype of XML in file.
xmlWriter.WriteStartElement("Employee");
//writing first element
xmlWriter.Close();
//closing writer
xmlDoc.Load(filename);
//loading XML file
XmlNoderoot = xmlDoc.DocumentElement;
//creating child nodes.
XmlElementchildNode1 = xmlDoc.CreateElement("ID");
XmlElementchildNode2 = xmlDoc.CreateElement("Name");
XmlElementchildNode3 = xmlDoc.CreateElement("Address");
//adding child node to root.
root.AppendChild(childNode1);
childNode1.InnerText = "1";
//writing inner text of childnode
root.AppendChild(childNode2);
childNode2.InnerText = "Alex";
root.AppendChild(childNode3);
childNode3.InnerText = "USA";
xmlDoc.Save(filename);
//saving xml file
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
Chris Anderson
21-Oct-2011Hi aken,
You can easily learn xml language from here:
http://www.w3schools.com/xml/
Kenny Tangnde
20-Oct-2011Hi Uttam Misra ,
this a nice article,if can you provide some xml language learn then will very good.
thanks!