G
Guest
Hello. Not very experienced using Streams of any kind, and Google didn't
save me...
I have some code that builds an Xml file and dumps it on my drive. It
works. Now, I want to do the same thing, but skip the file and just hold the
XmlDocument in memory and pass it around to various methods. Essentially, my
code is this:
-----------------------------
XmlDocument myXmlDocument = new XmlDocument();
MemoryStream myStream = new MemoryStream();
XmlTextWriter myWriter = new XmlTextWriter(myStream, Encoding.UTF8);
// Code to build the XmlDocument using myWriter
myWriter.WriteStartDocument();
myWriter.WriteStartElement(...
// continue building the XmlDocument using myWriter
myWriter.WriteEndDocument();
myXmlDocument.Load(myStream);
myWriter.Flush();
myWriter.Close();
return myXmlDocument;
---------------------
The exception occurs on the "myXmlDocument.Load(myStream)
line...System.Xml.XmlException: The root element is missing...
Anyone help me out? Thanks in advance.
save me...
I have some code that builds an Xml file and dumps it on my drive. It
works. Now, I want to do the same thing, but skip the file and just hold the
XmlDocument in memory and pass it around to various methods. Essentially, my
code is this:
-----------------------------
XmlDocument myXmlDocument = new XmlDocument();
MemoryStream myStream = new MemoryStream();
XmlTextWriter myWriter = new XmlTextWriter(myStream, Encoding.UTF8);
// Code to build the XmlDocument using myWriter
myWriter.WriteStartDocument();
myWriter.WriteStartElement(...
// continue building the XmlDocument using myWriter
myWriter.WriteEndDocument();
myXmlDocument.Load(myStream);
myWriter.Flush();
myWriter.Close();
return myXmlDocument;
---------------------
The exception occurs on the "myXmlDocument.Load(myStream)
line...System.Xml.XmlException: The root element is missing...
Anyone help me out? Thanks in advance.