By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,732 Members | 863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,732 IT Pros & Developers. It's quick & easy.

Deserialization of Unknown Object Type

P: n/a
I am implementing a DataStore/Settings object that stores objects in XML by
serializing the objects in XML and then associating these objects with key
names.

At some later point, I want to retrieve the object associated with a given
keyname, but I am running into trouble deserializing objects into the correct
object type.

Nearly all of the examples that I have found that use XmlSerializer pass in
a type ahead of time, but in my case the type is unknown.

I found an example in Dino Esposito's Applied XML Programming that shows how
it is possible to embed Type information alongsize an object's definition
within XML serialization (p.494) along the following lines:

SoapReflectorImporter imp = new SoapReflectionImporter();
XmlTypeMapping tm = imp.ImportTypeMapping(typeof(Employee));
XmlSerializer ser = new XmlSerializer(tm);

But, how could I determine the typeof parameter from a hunk of xml.

For example, I am looking for something along the following lines:

string BigHunkOfXmlWithTypeInfo
Type objType = TellMeYourType( BigHunkOfXmlWithTypeInfo )
mySerializer = XmlSerializer( objType )
objType MyObject = mySerializer.Deserialize( BigHunkOfXmlWithTypeInfo);

In particular, I would appreciate an example that shows how to perform this
type of deserialization.

Thanks,

Dan

Nov 12 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.