Rabu, 14 November 2007

Create XML through XmlWriterSettings => the fastest,efficient way instead using DOM


public static MemoryStream CreateXMltoStream(string emailsubject,string emailfrom,string emailto)


{


MemoryStream stream=new MemoryStream();


XmlWriterSettings thesettings = new XmlWriterSettings();


//writing to stream default is UTF8


Encoding x=System.Text.Encoding.GetEncoding("ISO-8859-1");


thesettings.Encoding = x;


thesettings.Indent = true;


//Write the header


thesettings.OmitXmlDeclaration = false;


thesettings.NewLineOnAttributes = true;


using (XmlWriter writer = XmlWriter.Create(stream, thesettings))


{


writer.WriteRaw(@"<!DOCTYPE MEDVRI_1 SYSTEM ""MEDVRI_1.dtd"">");


writer.WriteStartElement("MEDVRI_1");


writer.WriteStartElement("email");


writer.WriteStartElement("email.subject");


writer.WriteValue(emailsubject);


writer.WriteEndElement();


writer.WriteStartElement("email.from");


writer.WriteValue(emailfrom);


writer.WriteEndElement();


writer.WriteStartElement("email.to");


writer.WriteValue(emailto);


writer.WriteEndElement();


writer.WriteEndElement();


writer.WriteEndElement();


//free the memory


writer.Flush();


writer.Close();


return stream;


}


 


 

Tidak ada komentar: