Click here to Skip to main content
15,886,832 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, all

I would like to understand what is the best solution , if I would like to serialize/ de-serialize class to multiple XML files according to specific attribute

For example , I have class with two properties and need to serialize them into two separate xml files . And the opposite direction (deserialize).Save & Load from files


public class Student{

[SerializeTo(Path= "address.xml")]
public Address Address {get; set;}

[SerializeTo(Path= "grades.xml")]
public List<Grade> Grades {get; set;}
}

Is there any existing solution to such question ...


Very appreciate any help ,
Thanks,
Dima

What I have tried:

I tried to serialize object to single XML file , but it not exactly what I want , I need to split it to different XML files
Posted
Updated 18-Jun-19 10:59am
v2
Comments
BillWoodruff 18-Jun-19 15:25pm    
Why do you want to create multiple files ?
VDima77 18-Jun-19 15:39pm    
I would like to load properties by demand and sharing the same xml between two objects
BillWoodruff 18-Jun-19 19:25pm    
Do you need to save and load the two sets of Properties at different times ?

"sharing the same xml between two objects" Please explain this in more detail: if you have an XML file saved, can't any process access it ... as long as you deal with possible multiple access at the same time ?
MadMyche 18-Jun-19 17:33pm    
What you may want to try is an to create an "ExportToXML" method in the child classes to create their own XML files, and then another Export method in this class to act as a wrapper to the child methods
BillWoodruff 18-Jun-19 19:20pm    
Is this Java: C# has no 'SerializeTo Attribute ? If this is C#, what serialization method are you using ?

Do you need to save and load the two sets of Properties at different times ?

"sharing the same xml between two objects" Please explain this in more detail: if you have an XML file saved, can't any process access it ... as long as you deal with possible multiple access at the same time ?

1 solution

You serialize an "object" i.e. Class.

Doesn't matter if it's a "parent" or a "child". If the "object" is serializable as well as its children, then that "object graph" can be serialized.

Whether what you are doing is actually beneficial is another matter.
 
Share this answer
 
Comments
BillWoodruff 18-Jun-19 19:21pm    
My vote of #1: that is an astonishingly stupid non-answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900