Xml Serializer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use XmlSerializer to serial an object into a String that I can manipulate. It seems that all the XmlSerializer only works with Streams. Does someone have a snippet of code that allows me to use XmlSerializer that I can get a "String" value back. Thanks for the Help.
 
BobL said:
I am trying to use XmlSerializer to serial an object into a String
that I can manipulate. It seems that all the XmlSerializer only
works with Streams. Does someone have a snippet of code that allows
me to use XmlSerializer that I can get a "String" value back. Thanks
for the Help.

I'm not familar with the XmlSerializer, but I think what you want is a
MemoryStream. Then you can use
System.Text.Encoding.Unicode.GetString(memstream.GetBuffer()) when you want
the string.

- Pete
 
I am trying to use XmlSerializer to serial an object into a String that I
can manipulate. It seems that all the XmlSerializer only works with
Streams. Does someone have a snippet of code that allows me to use
XmlSerializer that I can get a "String" value back. Thanks for the Help.

What object is it? If the object itself isn't serializeable, I don't think
it'll work anyway...
 
Have a go at:

XmlSerializer xser = new XmlSerializer (typeof (Participant));

StringBuilder sb = new StringBuilder ();
StringWriter sw = new StringWriter (sb);
xser.Serialize(sw, obj);

Console.WriteLine (sb.ToString ());
Console.ReadLine ();

Participant is just some class that is being serialized.
 
Back
Top