Thanks all for the information.
Below are my original codes that will create the xml file physically:
private void convertDataTableToXML()
{
// Duplicate the table and add it to a temporary DataSet
DataSet dataset = new DataSet();
DataTable datatable = premiumTable.Copy();
dataset.Tables.Add(datatable);
// Save the temporary DataSet to XML
StreamWriter streamwriter = new StreamWriter("C://XMLDoc.xml");
dataset.WriteXml(streamwriter);
streamwriter.Close();
}
However, instead of using StreamWriter, I change to MemoryStream.
Below is the codes:
MemoryStream ms = new MemoryStream();
dataset.WriteXml(ms);
ms.Close();
How to I reference the xml file created by MemoryStream for later use? Eg, I
need to extract a node value from the xml file.
Thanks.
Thanks,
Siew Yee
"Jon Skeet [C# MVP]" wrote:
<"=?Utf-8?B?U2lldyBZZWU=?=" <Siew Ye*@discussions.microsoft.com>>
wrote: I need convert data from DataTable to XML file. Understand that I can use
the following command to do it. However, there will be existing file be
created. Is there any other ways which there wont be file created? I only
need to store it in memory.
DataSet.WriteXml can write to a stream, a TextWriter, an XmlWriter or a
file. You could use a MemoryStream, a StringWriter, or an XmlWriter
backed by either of them.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too