This tip demonstrates how to create XML file using C#
StringWriter stringwriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringwriter); xmlTextWriter.Formatting = Formatting.Indented; xmlTextWriter.WriteStartDocument(); xmlTextWriter.WriteStartElement("root"); xmlTextWriter.WriteStartElement("information"); xmlTextWriter.WriteElementString("FirstName", "First Name"); xmlTextWriter.WriteElementString("LastName", "Last Name"); xmlTextWriter.WriteEndElement(); xmlTextWriter.WriteEndDocument(); XmlDocument docSave = new XmlDocument(); docSave.LoadXml(stringwriter.ToString()); //write the path where you want to save the Xml file docSave.Save(@"c:\Information.xml");
Output XML :
<?xml version="1.0" encoding="UTF-16"?> <root> <information> <FirstName>First Name</FirstName> <LastName>Last Name</LastName> </information> </root>