Saturday, August 13, 2011

Creating a Simple XML Document ASP.net

namespace WriteToXML
{
using System;
using System.Xml;
///
/// Summary description for Class1.
///

public class Class1
{
public Class1()
{
}
public static int Main(string[] args)
{
try
{
// Creates an XML file is not exist
XmlTextWriter writer = new XmlTextWriter("C:\\temp\\xmltest.xml", null);
// Starts a new document
writer.WriteStartDocument();
//Write comments
writer.WriteComment("Commentss: XmlWriter Test Program");
writer.WriteProcessingInstruction("Instruction","Person Record");
// Add elements to the file
writer.WriteStartElement("p", "person", "urn:person");
writer.WriteStartElement("LastName","");
writer.WriteString("Chand");
writer.WriteEndElement();
writer.WriteStartElement("FirstName","");
writer.WriteString("Mahesh");
writer.WriteEndElement();
writer.WriteElementInt16("age","", 25);
// Ends the document
writer.WriteEndDocument();
}
catch (Exception e)
{
Console.WriteLine ("Exception: {0}", e.ToString());
}
return 0;
}
}
}









No comments:

Post a Comment