473,387 Members | 1,942 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,387 software developers and data experts.

Xml Serialization of a custom class

If I have a class that holds two string values, so for instance.

Public Class myClass{

private string s1;
private string s2;

public myClass(str1, str2){
s1 = str1;
s2 = str2;
}
}

And then another class which I wish to serialize using an
XmlSerializer that holds an instance variable of type myClass, so for
instance.

Public Class mySerializable{

public string str1;
public string str2;
public myClass mc;

public mySerializable(s1, s2, myClass){
str1 = s1;
str2 = s2;
mc = myClass;
}
}

When I Serilize this using an XML Serializer, the values come out fine
for str1 and str2, but for mc it is empty.

My Question is...Is there a way to specify in myClass somehow that
when it is serialized by an XmlSerializer to simply output s1 as its
value? If not, is there any work around to make this work?

Thanks,

Eric Workman
Nov 15 '05 #1
3 1897
"Eric Workman" <er**********@yahoo.com> wrote in message
news:68**************************@posting.google.c om...

XML serialization only serializes public fields and properties (and
therefore requires less trust). If you want full-fidelity, you'll need to
use runtime serialization.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com


Nov 15 '05 #2
Really what I need is the objects to be serialized into xml for use in
an XmlDocument object, is there any way to do that using Runtime
Serialization?

Thanks Again,

Eric Workman

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
If you can deal with the overhead, you can use the soap formatter. Otherwise
you'll need to write an XML formatter for runtime serialization (or expose
the fields/properties).

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com

"Eric Workman" <er**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Really what I need is the objects to be serialized into xml for use in
an XmlDocument object, is there any way to do that using Runtime
Serialization?

Thanks Again,

Eric Workman

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #4

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

Similar topics

0
by: psy000 | last post by:
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
10
by: SStory | last post by:
My app is near completed for the basic feature of version 1.0. I have an extensive object model and I now want to persist my objects using serialization. I have chosen binaryformatter to...
4
by: Joe | last post by:
I would like to call a method of an object before the object is serialized. I currently have a surrogate that I use for deserilization and was thinking I could use one for serialization but that...
1
by: Rucha | last post by:
We are using ACAServices in our project, and are passing entity classes as parameters to the ACAServiceMethod. We are using a private variable entityState to indicate whether the entity is...
15
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with...
3
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm...
1
by: Paez | last post by:
Hi There. This post is a extension of thread "Serialize or not to Serialize", on 5 of December of 2006. The reason why my teacher insists that a WS cannot return a Dataset is due to low rate...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.