-
February 21st, 2015, 12:17 AM
#1
serializing objects to XML
Folks,
Is it possible to achieve random access with XmlSerializer? I would like to be able able to store multiple objects of different types in the same XML file (adding them at different times, not all at once). I would like to be able to de-serialize them one at a time. I would like to update them one at a time.
Is XmlSerializer a right kind of tool for this?
Is there something better (short of setting up a proper database)?
Am I looking for something that goes by a different name?
Any suggestion, insight or reference is really appreciated!
- Nick
-
February 22nd, 2015, 11:36 AM
#2
Re: serializing objects to XML
Will the types be known ahead of time or do you want to randomly add items of different types?
-
February 22nd, 2015, 05:52 PM
#3
Re: serializing objects to XML
 Originally Posted by Arjay
Will the types be known ahead of time or do you want to randomly add items of different types?
The types will not be known in advance. That's the reason why XmlSerializer looks appealing. I can extract the type information, so I shouldn't need to know it ahead of time
Code:
XmlSerializer xmlSerializer = new XmlSerializer(braveNewObject.GetType());
I have picked up that thought here: Serialize multiple objects of different types into single XML using XDocument
Of course, there may be other options, which I'm not even aware of, which are just as nice.
Last edited by kender_a; February 22nd, 2015 at 08:40 PM.
-
February 22nd, 2015, 09:37 PM
#4
Re: serializing objects to XML
Serializing unknown types into xml won't be a problem; however, to deserialize the xml back into objects, you need to know what the objects will be.
If you structure your xml correctly, you can effectively store the data as different 'objects', but in actuality, the underlying types need to be known during deserialization.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|