Welcome to AspAdvice Sign in | Join | Help

How To Write To An XML File

using System;
using System.Xml; 
namespace ConsoleApplication3
{

class Class1
{

static void Main(string[] args)
{

string filename = @"c:\authors.xml";

XmlTextWriter textwriter = new XmlTextWriter(filename,null);

textwriter.Formatting = Formatting.Indented;
textwriter.WriteStartDocument();
textwriter.WriteStartElement("Author"); 
textwriter.WriteStartElement("Name","Steven M. Swafford");
textwriter.WriteElementString("URL","http://www.aspalliance.com");
textwriter.WriteEndElement();
textwriter.WriteEndElement();
textwriter.WriteEndDocument(); 
textwriter.Flush();
textwriter.Close();
}
}
}
Published Tuesday, March 15, 2005 11:38 AM by sswafford
Filed under:

Comments

No Comments

New Comments to this post are disabled