D
D
Hi,
I am trying to instantiate an instance of XPathDocument after serializing
XML into a memory stream. Here is my method that uses XmlSerializer
public MemoryStream SerializeXMLSelectedApplication()
{
System.IO.MemoryStream stream = new MemoryStream();
try
{
XmlSerializer serializer = new XmlSerializer(typeof(Subject));
serializer.Serialize(stream, this);
}
catch(SystemException ex)
{
Console.WriteLine(ex.Message);
}
return stream;
}
//Using the return stream, I attempt to instantiate XPathDocument
XPathDocument doc = new
XPathDocument(session.Subject.SerializeXMLSelectedApplication());
The line of code above causes an error message that reads "root element
missing." So I am thinking that I am not using my memory stream properly
for the XPathDocument constructor. Your help will be greatly appreciated.
Note: I've tested my code that uses the XmlSerializer using TextWriter
before using MemoryStream and it works perfectly.
I am trying to instantiate an instance of XPathDocument after serializing
XML into a memory stream. Here is my method that uses XmlSerializer
public MemoryStream SerializeXMLSelectedApplication()
{
System.IO.MemoryStream stream = new MemoryStream();
try
{
XmlSerializer serializer = new XmlSerializer(typeof(Subject));
serializer.Serialize(stream, this);
}
catch(SystemException ex)
{
Console.WriteLine(ex.Message);
}
return stream;
}
//Using the return stream, I attempt to instantiate XPathDocument
XPathDocument doc = new
XPathDocument(session.Subject.SerializeXMLSelectedApplication());
The line of code above causes an error message that reads "root element
missing." So I am thinking that I am not using my memory stream properly
for the XPathDocument constructor. Your help will be greatly appreciated.
Note: I've tested my code that uses the XmlSerializer using TextWriter
before using MemoryStream and it works perfectly.