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
Re: serializing objects to XML
Will the types be known ahead of time or do you want to randomly add items of different types?
Re: serializing objects to XML
Quote:
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.
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.