only My site

Wednesday, July 23, 2008

XmlTextWriter & MemoryStream


private byte[] GenerateXXXXXML()
{
byte[] distBytes = new byte[1];

using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
XmlTextWriter xtw = new XmlTextWriter(ms, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.WriteProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
xtw.WriteStartElement("PRODValidation");
xtw.WriteAttributeString("xmlns", "http://www.XXX.com/PRODUCT/validate");

// charge type
xtw.WriteStartElement("Query");
xtw.WriteAttributeString("name", "TABLENAME");
xtw.WriteStartElement("Parameters");
xtw.WriteStartElement("Param");
xtw.WriteAttributeString("name", "");
xtw.WriteAttributeString("value", "");
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteStartElement("Result");
xtw.WriteStartElement("Status");
xtw.WriteEndElement();
xtw.WriteStartElement("AdditionalInfo");
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndElement();

xtw.WriteEndElement();
xtw.Flush();
ms.Flush();
distBytes = ms.ToArray();
xtw.Close();
}

return distBytes;
}

No comments: