473,509 Members | 8,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serializing object to XmlDocument (or string)

Tom
I am on .NET 2.0 and am trying to serialize an object to an XmlDocument
(or a string which I can then create an XmlDocument from).

What I have so far is (User is my class);

XmlSerializer x = new XmlSerializer(typeof(User));
MemoryStream memStream = new MemoryStream();

How can I get this to a string or an XmlDocument?

The serialization works fine as if I serialize to a text file (using
StreamWriter), everything looks fine.

I've try converting to bytes, reading on XmlWriter, but nothing seems
to work.

Thanks,

Nov 15 '06 #1
1 9478
Tom
Ok, I figured it out about 5 mins after posting so I thought I would
post my results.

The problem was that after writing to the stream, the stream pointer
was at the end of the stream so when XmlDocument.Load() tried loading
it, it returned "Root Element Missing".

I just moved the pointer back like this:

memStream.Seek(0, System.IO.SeekOrigin.Begin);

Once I did this, XmlDocument.Load() worked fine.

Tom wrote:
I am on .NET 2.0 and am trying to serialize an object to an XmlDocument
(or a string which I can then create an XmlDocument from).

What I have so far is (User is my class);

XmlSerializer x = new XmlSerializer(typeof(User));
MemoryStream memStream = new MemoryStream();

How can I get this to a string or an XmlDocument?

The serialization works fine as if I serialize to a text file (using
StreamWriter), everything looks fine.

I've try converting to bytes, reading on XmlWriter, but nothing seems
to work.

Thanks,
Nov 15 '06 #2

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

Similar topics

3
10111
by: Nathan | last post by:
Hi: Here's what I am trying to do, pass a string array between two pages using Server.Transfer method: Sending page I do this: private string arrFCInfo=new String; //Property - read only...
5
1885
by: AC | last post by:
I've put some strings into a stack, and now I want to convert the stack to an string based array. Here's what I'm trying to do (this returns a cast error) string results =...
3
3627
by: XenofeX | last post by:
How can i call to object from string variable ? For instance string x = "textBox1"; i want to call the object which name is stored in the x string variable. The most important thing is the...
1
4112
by: bryja_klaudiusz[at]poczta[dot]fm | last post by:
Hi, How to convert object to string? I try procedure like this (when I have byte array I convert it to string): public byte ObjectToByteArray(Object obj) { MemoryStream fs = new...
4
15037
by: Chumley Walrus | last post by:
This may be easier than I think, but I need to find a quick way to change a datetime object to string, as the following mydateobject = mydateobject.ToString(); renders the error: Cannot...
9
10510
by: Andy Sutorius | last post by:
Hi, I am receiving the error when compiling the project, "cannot implicitly convert type object to string". The error points to this line of code and underlines the dtrRecipient:...
7
1340
by: c676228 | last post by:
Hi all, I have the code: If Session("Plan") = "Plan I" Then... I was just aware of that the Session("Plan") is an object, with String value "Plan I", but I don't know how to compare them and it...
3
28515
by: Wallace | last post by:
Hai, Can anyone tell how to convert an object into string? Please help me.... urgent.. Thanx in advance...
1
1120
by: igalep132 | last post by:
hello is it possible to convert an object to string ? for exmp Dog snow = new Dog(); string name = snow (i want to get a dog name (object) as a string) 10X
4
14176
polymorphic
by: polymorphic | last post by:
I need to convert a data object to string. Currently, my script follows as: strTitle = CStr(<%=mobjSystem.DescrShort %>) When this is compiled it appears as: strTitle = CStr(SOPs -...
0
7237
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
7137
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
7347
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,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.