Pages

Saturday, April 17, 2010

Create XML file using C#

using System.Data;
using System.Drawing;
using System.Xml;using System.IO;
//codeXmlTextWriter xmlWriter = new XmlTextWriter("temp.xml", System.Text.Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
xmlWriter.WriteStartElement("root");
xmlWriter.Close();
// creation complete
doc = new XmlDocument();doc.Load("temp.xml");
XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "firstnode", ""); // creating NodenewNode.InnerText = “Content”; // set your contentdoc.DocumentElement.AppendChild(newNode); //Adds a Node
doc.Save("temp.xml");

No comments:

Post a Comment