Take a look at this code, which writes the XML schema *and* XML data from a DataSet object to a file:
Dim oTextWriter As System.IO.TextWriter
Dim oXMLSerializer As System.Xml.Serialization.XmlSerializer
oTextWriter = New IO.StreamWriter("C:\myds.txt")
oXMLSerializer = New Xml.Serialization.XmlSerializer(GetType(System.Data.DataSet))
Call oXMLSerializer.Serialize(oTextWriter, oDataSet)
This just works great. I say "great" because it writes both the SCHEMA and the DATA to that target file.
What I need, though, is a way to write all that data to a String variable, in memory. I know about DataSet.ReadXmlSchema() and DataSet.ReadXml(), but they do not do what the above does--they return only one or the other at a time. I want the in-memory equivalent of what happens above--schema and data together, happy and free--only in memory, not to a file.
(Naturally, I don't want something as inelegant as writing all this to a file, then reading it back into a variable and then destroying the temp file. There's a better way.)
I believe that this can be done by somehow employing a System.IO.MemoryStream, and perhaps supplying that to the StreamWriter constructor above (instead of a filepath). I'm just too dumb/lazy to make it happen, however.
Can someone show me how?
Thanks a lot.