Solved

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

Posted on 2003-10-27
6
502 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now