Deserializing - Can this be done?

G

Guest

I want to be able to deserialize data contained within a XML file to a data
structure. This I know how to do. However, what I want to be able to do is
the following:
1. Serialize multiple "C# classes" into a single XML file. One at a time.
2. Deserialize each "C# class" from the XML file. One at a time.

Is this possible? I don't see a way to do this. If it isn't possible does
anyone have a suggestion on how to get around a problem I have. I have many
data structures that I need to save to disk and later retrieve when a program
runs. The data structures are contained in nodes of a TreeView list. If I
serialize each structure one-by-one I may have hundreds of XML files. I want
to group certain TreeView node-paths all under a single XML file to have
fewer XML files to manage and thus make things easier. How could I go about
doing this?
 
S

sloan

Maybe you can get some ideas here
9/21/2005
XmlSerialization with IDictionary and CollectionBase Objects
http://sholliday.spaces.live.com/?_...ogview&_c=blogpart&partqs=amonth=9&ayear=2005


But for
#1
I'd write a "wrapper" object to handle this. Like, if you needed to
serialize a Plant object, Person object, Animal object.........you could
create a
ThingWrapper class, with 3 properties (1 for a Plant, 1 for a Person, 1 for
an Animal), and serialize the ThingWrapper.
OR
You can do each thing individually, and roll your own "xml merger", but
you'd have to do alot of work here. And when you needed to pull them out,
you'd have to use SelectNodes or SelectSingleNode, and get the innerXml to
serialize each object. This is why I mention the ThingWrapper above.

#2 related to #1.

Check out my blog code...........

But the ThingWrapper is where I'd look to. That, or using the blog code to
figure out how to serialize collections of objects.
 
G

Guest

Great minds must think alike! :) Sloan's first comment got me to thinking
that an array of these objects could be written to an XML file. I just
completed the test code and sure enough it works.

Thanks to you both.
--
-----------
Thanks,
Steve


Kevin Spencer said:
You can put them into a Generic Collection, and serialize the Collection.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top