I am currently exporting a database table with huge data (100,000+ entries) to an xml file using the XmlTextWriter class, and I am writing directly to a file on a physical disk.
_XmlTextWriterObject = new XmlTextWriter(_xmlFilePath, null);
While my code is working fine, my question is, what is the best approach? Should I instead write all the xml in the memory stream first, and then write the XML document to the physical file from the memory stream? And what are the implications for memory / performance in both cases?
EDIT
Sorry that I could not convey what I wanted to say. Thanks Ash for pointing out. I will actually use XmlTextWriter, but I wanted to say whether to pass the string of the physical file to the XmlTextWriter constructor (or, as John suggested, to the method XmlTextWriter.Create()) or to use api based on the stream. My current code is as follows:
XmlWriter objXmlWriter = XmlTextWriter.Create(new BufferedStream(new FileStream(@"C:\test.xml", FileMode.Create, System.Security.AccessControl.FileSystemRights.Write, FileShare.None, 1024, FileOptions.SequentialScan)), new XmlWriterSettings { Encoding = Encoding.Unicode, Indent = true, CloseOutput = true });
using (objXmlWriter)
{
}
source
share