Solved

vb.net - XML - Serialize to string and not to file/stream

Posted on 2003-10-27
6
505 Views
Last Modified: 2007-12-19
Hi
Please tell me how I can serialize to a string, not to a file.

For example:
Dim serializer as New XmlSerializser(something.GetType())
Dim result as string
serializer.serialize(result, something.GetType())


See how I want the result to be put into a string, not written to a stream.

Thanks
Daniel
0
Comment
Question by:jasww
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
bacon7181 earned 125 total points
ID: 9626525
               Dim Serializer As New System.Xml.Serialization.XmlSerializer(something.GetType())
                ' We will serialize to a Memory Stream
                Dim ms As New MemoryStream
                Serializer.Serialize(ms, something)
                ' Then convert the memory stream to a string
                Dim myString As String = Convert.ToBase64String(ms.GetBuffer())
0
 

Author Comment

by:jasww
ID: 9626564
Thanks - I just need the IMPORTS "foo.bar.memory"  part for MemoryStream object please...
0
 
LVL 3

Expert Comment

by:bacon7181
ID: 9626586
System.IO
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:jasww
ID: 9626796
OK,
all I am getting is base64 garbage.
I need the original string.
convert.ToString() does not work.

Thanks
Daniel
0
 

Author Comment

by:jasww
ID: 9626818
It's ok


System.Text.Encoding.UTF8.GetString(ms.getBuffer())
0
 
LVL 10

Expert Comment

by:GoodJun
ID: 9626823
dim buffer as new MemoryStream()
dim formatter as New XmlSeriallizer(yourObject.GetType)

formatter.Serialize(buffer, yourObject)

dim output as string
output=system.text.encoding.ascii.getstring(buffer.ToArray)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question