473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how do I write the output of a serialized class as a string?

Hi:

My serialized class is ending up in a XML.XMLTEXTRIDER

How do I write from that to a string? It seems as if it is storing it as a
stream? How do I read the contents of a stream into a string?

Thanks!
Nov 20 '05 #1
4 1064
"Tarren" <noemailplease@thankyou> wrote in message news:O4**************@TK2MSFTNGP09.phx.gbl...
My serialized class is ending up in a XML.XMLTEXTRIDER
I don't know if that's incoming (XmlTextReader) or outgoing
(XmlTextWriter)?

If you are holding an XmlTextReader named ''reader,''
then you can read the XML into a string like this,

Dim xmlStr As String
Dim doc As XmlDocument = New XmlDocument( )
' Uncomment next statement if you care about whitespace.
' doc.PreserveWhitespace = True
doc.Load( reader)
xmlStr = doc.OuterXml

If you are going to hold an XmlTextWriter named ''writer,'' then wrap
it around a System.IO.StringWriter before you start serializing an
object named ''myObject'' to an XmlSerializer named 'serializer'',

Dim xmlStr As String
Dim strWriter As System.IO.StringWriter

strWriter = New System.IO.StringWriter( New System.Text.StringBuilder( ) )
writer = New XmlTextWriter( strWriter )
serializer.Serialize( writer, myObject)
xmlStr = strWriter.ToString( )
How do I read the contents of a stream into a string?


Wrap the Stream in a System.IO.StreamReader and then call
ReadToEnd( ),

Dim streamStr As String
streamStr = New System.IO.StreamReader( stream).ReadToEnd( )
Derek Harmon
Nov 20 '05 #2
* "Tarren" <noemailplease@thankyou> scripsit:
My serialized class is ending up in a XML.XMLTEXTRIDER

How do I write from that to a string? It seems as if it is storing it as a
stream? How do I read the contents of a stream into a string?


Classes 'StreamWriter' or, more low-level, 'MemoryStream' +
'System.Text.Encoding.GetString'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
thanks all! I ended up using a MemoryStream

Most of the examples I had seen involved reading from a .xml file, and so
those examples use a FileStream
but MemoryStream did the trick.

:)

"Tarren" <noemailplease@thankyou> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
Hi:

My serialized class is ending up in a XML.XMLTEXTRIDER

How do I write from that to a string? It seems as if it is storing it as a stream? How do I read the contents of a stream into a string?

Thanks!

Nov 20 '05 #4
Hi Tarren,

I did not notice this thread, the memorystream does it. However the
stringwritter does it mostly more easy.

A sample
Serialize
\\\\
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.tostring
///
Deserialize
\\\
Dim sr As New System.IO.StringReader(mystring)
Dim ds2 As New DataSet
ds2.ReadXml(sr)
///

Sorry that I missed the thread, however the memorystream does it with the
streamreader also, but you need an extra step for that.

Cor
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
5
by: Geo | last post by:
Hi, Im running into a strange problem here! I have created a linked server on one of my SQL Servers (local server). Lets call the linked server as LS1. I have an sproc which resides on the...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
2
by: andrew lowe | last post by:
Hi, Please bear with me on this problem, first I'll give you some background: I have an object that contains a DateTime field which i pass to a webservice public class Foo { public DateTime...
0
by: Wim Hollebrandse | last post by:
Here's the scenario. I'm serializing a particular object, which contains other objects as properties. I have this particular enum type that won't get included in the serialized XML. For...
4
by: Bill Nguyen | last post by:
I wonder if I can write to an XML file using column structure (and column names) of an SQLserver table. for example: Table A: column1 int column2 char(30) column3 date XML output:
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
2
by: thecoolone | last post by:
I am trying to implement the yahoo search api using php. I prefer to use PHP serialized to get the result of the search displayed. Right now i get the output like: Array ( =Array ( =web ...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.