|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to serialize into a string ?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 Show quoteHide quote "Cerebrus" <zorg***@sify.com> wrote in message news:1147854868.876026.141930@y43g2000cwc.googlegroups.com... > 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. > Try setting the StringWriter.Encoding property to Encoding.UTF8Encoding?
====================== Clive Dixon Digita Ltd. (www.digita.com) Show quoteHide quote "Peter Stojkovic" <d**@gmx.net> wrote in message news:uispKMbeGHA.1792@TK2MSFTNGP03.phx.gbl... > 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 > > > > > > "Cerebrus" <zorg***@sify.com> wrote in message > news:1147854868.876026.141930@y43g2000cwc.googlegroups.com... >> 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. >> > > The endoding is readonly.
Show quoteHide quote "Clive Dixon" <clived.noluncheonm***@digita.noluncheonmeat.com> wrote in message news:ehxsn6beGHA.380@TK2MSFTNGP04.phx.gbl... > Try setting the StringWriter.Encoding property to Encoding.UTF8Encoding? > > ====================== > Clive Dixon > Digita Ltd. (www.digita.com) > > > "Peter Stojkovic" <d**@gmx.net> wrote in message > news:uispKMbeGHA.1792@TK2MSFTNGP03.phx.gbl... >> 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 >> >> >> >> >> >> "Cerebrus" <zorg***@sify.com> wrote in message >> news:1147854868.876026.141930@y43g2000cwc.googlegroups.com... >>> 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. >>> >> >> > > 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) Show quoteHide quote "Peter Stojkovic" <d**@gmx.net> wrote in message news:%23YPYo9beGHA.764@TK2MSFTNGP05.phx.gbl... > The endoding is readonly. > > > "Clive Dixon" <clived.noluncheonm***@digita.noluncheonmeat.com> wrote in > message news:ehxsn6beGHA.380@TK2MSFTNGP04.phx.gbl... >> Try setting the StringWriter.Encoding property to Encoding.UTF8Encoding? >> >> ====================== >> Clive Dixon >> Digita Ltd. (www.digita.com) >> >> >> "Peter Stojkovic" <d**@gmx.net> wrote in message >> news:uispKMbeGHA.1792@TK2MSFTNGP03.phx.gbl... >>> 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 >>> >>> >>> >>> >>> >>> "Cerebrus" <zorg***@sify.com> wrote in message >>> news:1147854868.876026.141930@y43g2000cwc.googlegroups.com... >>>> 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. >>>> >>> >>> >> >> > > ....but remember that the string you get still consists of a sequence of
16-bit characters. ====================== Clive Dixon Digita Ltd. (www.digita.com) Show quoteHide quote "Peter Stojkovic" <d**@gmx.net> wrote in message news:uispKMbeGHA.1792@TK2MSFTNGP03.phx.gbl... > 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 > > > > > > "Cerebrus" <zorg***@sify.com> wrote in message > news:1147854868.876026.141930@y43g2000cwc.googlegroups.com... >> 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. >> > >
DataView RowFiltering
Byte to Chr - not correctly translated!! GetDefaultPrinter Saving a JPG from the web to local disk User Software Settings and System Software Settings in Windows Regsitry .NET Remoting Confusion over namespaces CSV file reading every other record... String Name to a User Control? locate a desired row |
|||||||||||||||||||||||