473,396 Members | 2,011 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,396 software developers and data experts.

How to serialize two different objects into one XML file

I have two different classes as follow and in my application I create two
diiferent objects of them and I want to srialize those two objects into one
XML file
because they are related ,Is there an suggestion on how to do that .Maybe I
need to combine these two classes and work on one class only ,right??

Thanks for your time.
Class1:
public class EnviroVars
{
private string m_reportServerName;
private string m_reportName;

public EnviroVars(){}
// Report Server Name property
public string RSName
{
get {return m_reportServerName;}
set {m_reportServerName=value;}
}
// Report Name property
public string ReportName
{
get {return m_reportName;}
set {m_reportName=value;}
}
}
================================================== ==========================
====
Class2:

public class ReportParams
{
private ParameterValue[] m_ReportParams;
private int m_MaxReportParas;

public ReportParams(int MaxReportParas)
{
m_MaxReportParas=MaxReportParas;
m_ReportParams=new ParameterValue[MaxReportParas];
}

//Here is the implementation of the indexer by array index
public ParameterValue this[int index]
{
get
{
// Check for out of bounds condition
if ( index < 0 || index > m_ReportParams.Length- 1 )
return null;
// Return employee based on index passed in
return m_ReportParams[index];
}
set
{
// Check for out of bounds condition
if ( index < 0 || index > m_MaxReportParas - 1 )
return;
// Add new Parameter
m_ReportParams[index]= value ;
}
}

}

Nov 16 '05 #1
1 2926
Les
You may be missing what serialize does, but none the less: if you want to
make 2 classes into 1 class, then one of the classes must be a subclass of
the other and you can make them both of the class that is not a subclass. Or
you can make them into 1 class by having them both be a subclass of a common
superclass. They can both become the type of the superclass.

If you mean you want to take these 2 objects and combine them into 1 object,
then niether of these approaches will work, but rather; you will need to have
a class that has all of the compenents of both classess--a "superclass" and
make a merge merge method for the superclass to "absorbe" the subclass
objects into it.

"ALI-R" wrote:
I have two different classes as follow and in my application I create two
diiferent objects of them and I want to srialize those two objects into one
XML file
because they are related ,Is there an suggestion on how to do that .Maybe I
need to combine these two classes and work on one class only ,right??

Thanks for your time.
Class1:
public class EnviroVars
{
private string m_reportServerName;
private string m_reportName;

public EnviroVars(){}
// Report Server Name property
public string RSName
{
get {return m_reportServerName;}
set {m_reportServerName=value;}
}
// Report Name property
public string ReportName
{
get {return m_reportName;}
set {m_reportName=value;}
}
}
================================================== ==========================
====
Class2:

public class ReportParams
{
private ParameterValue[] m_ReportParams;
private int m_MaxReportParas;

public ReportParams(int MaxReportParas)
{
m_MaxReportParas=MaxReportParas;
m_ReportParams=new ParameterValue[MaxReportParas];
}

//Here is the implementation of the indexer by array index
public ParameterValue this[int index]
{
get
{
// Check for out of bounds condition
if ( index < 0 || index > m_ReportParams.Length- 1 )
return null;
// Return employee based on index passed in
return m_ReportParams[index];
}
set
{
// Check for out of bounds condition
if ( index < 0 || index > m_MaxReportParas - 1 )
return;
// Add new Parameter
m_ReportParams[index]= value ;
}
}

}

Nov 16 '05 #2

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

Similar topics

0
by: James Sleeman | last post by:
Hi all, i just spent an hour rifling through code to find the cause of a problem only to find it's an oddity with serialization and recursive objects, so figured I'd post for the next person who...
1
by: Tom Rahav | last post by:
Hi! My question is whether it's possible to serialize an object into a binary file from one application, and then deserialize this object in a different application that has the same class. I...
2
by: Hollywood | last post by:
After doing a search through google's archives of this list, I didn't see what I was looking for so here goes... Is it possible to serialize/deserialize multiple objects from a single XML file? ...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
10
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
5
by: Arjen | last post by:
Hello, I have an array "aPeople" with people objects which I serialize like this: XmlSerializer x = new XmlSerializer( typeof(People) ); TextWriter writer = new StreamWriter( "data.xml" );...
2
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
3
by: Gislain | last post by:
Hello, I'm looking for a best way to serialize multiple / different object in the same XML file, and of course, how can i deserialize it. Actualy, when i serialize the first object in XML...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.