Solved

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

Posted on 2003-10-27
6
503 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

20 Experts available now in Live!

Get 1:1 Help Now