Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: XML Serialization/Deserialization  (Read 1675 times)
serial
Customers
Community Member
*****
Posts: 380


« on: September 26, 2010, 06:31:30 PM »

Well I've been working on XML serialization for my game objects.  It is all working fine but one question has popped up that I can't seem to google the anwser to.

How can I find out what type of object/class has been saved to the xml file? For example I have two classes Cat and Dog.  I have a file for Dogs and a File for Cats. I want to be able to load the XML file without first knowing if it is a cat or dog file.

All of the examples that I can find predetermine the type of object it is going to be in the loading functions. 
Logged
Mithrandir
Community Member
*
Posts: 325


« Reply #1 on: September 26, 2010, 08:15:06 PM »

You could read the XML file and check for cat or dog elements before deserializing.
Logged
ZaPPZion
Moderator
Community Member
*****
Posts: 555


« Reply #2 on: September 27, 2010, 04:39:28 AM »

Or use inheritance to have both the cat and dog be an animal, load the animal, it will then be of the valid type, you can then determine which of the two it is by using reflection
Logged

Check out my website: www.bartkuipers.com
serial
Customers
Community Member
*****
Posts: 380


« Reply #3 on: September 28, 2010, 02:45:14 AM »

Both of those ideas did cross my mind.  Will have to try them. 
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks