What's wrong with doing this?

M

MikeL

I need to get the XML doc from the deserialized type (seResults) returned
from a web service. Here's what I came up with - thanks in advance:

System.Xml.Serialization.XmlSerializer s = new
System.Xml.Serialization.XmlSerializer(typeof(seResults));
// First, get the size of the result XML doc and initialize the byte array:
Stream mm = new MemoryStream();
s.Serialize(mm, results);
byte[] byteArray = new byte[mm.Length];
mm = new MemoryStream(byteArray,0,(int)mm.Length);
// Now serialize the result:
s.Serialize(mm, results);
// Now convert it to a string:
ASCIIEncoding encoding = new ASCIIEncoding( );
string str = encoding.GetString(byteArray);
str = str.Trim();
MessageBox.Show(str);
 
M

MikeL

Here's better code (I originally didn't see the GetBuffer function):

System.Xml.Serialization.XmlSerializer s = new
System.Xml.Serialization.XmlSerializer(typeof(seResults));

// First, get the size of the result XML doc and initialize the byte array:
MemoryStream mm = new MemoryStream();

// Now serialize it:
s.Serialize(mm, results);

// Now convert it to a string:
ASCIIEncoding encoding = new ASCIIEncoding( );
string str = encoding.GetString(mm.GetBuffer());
str = str.Trim();
MessageBox.Show(str);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top