How to serialize into a string ?

  • Thread starter Thread starter Peter Stojkovic
  • Start date Start date
P

Peter Stojkovic

I am using a xlmserializer , to write into a file .
serializer.Serialize(writer, po, ns)

Everything works fine.

But instead of writing into a file, i want serialize into a string.

How can I do this ???





Thanks for any hint

Peter
 
Hi,

Try this :
------------------------------------------
' I assume po is the object you want to serialize.
Dim sw as New StringWriter()
serializer.Serialize(sw, po)
' Get the serialized string
Console.WriteLine(sw.ToString())
------------------------------------------
HTH,

Regards,

Cerebrus.
 
Thanks a lot :

The result for serialization is:

<?xml version="1.0" encoding="utf-16"?>
.....

But how can I controt which encoding is used ??
Now always UTF-16 is used.
But I need ti use utf-8

How can i switch to utf-8 instead of using itf-16 ?


Peter
 
....but remember that the string you get still consists of a sequence of
16-bit characters.

======================
Clive Dixon
Digita Ltd. (www.digita.com)
 
Sorry yes, that's what comes from trying to quote from vague memory. I think
the answer is to derive your own class from StringWriter and override the
virtual Encoding property to return UTF8Encoding.

======================
Clive Dixon
Digita Ltd. (www.digita.com)
 
Back
Top