?
Solved

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

Posted on 2003-10-27
6
Medium Priority
?
522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
bacon7181 earned 375 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
Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

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