Just to add a couple things to my previous XML serialization post. I've been trying to serialize a couple classes that are the backbone for track data in AAVOnline. One of them, PilotData, stores each pilot's information and an ArrayList of their DataPoint's. In order for XML Serialization to work, the compiler *must* know the types of every piece of XML data at compile-time. When you have a collection such as an ArrayList this is unknown. The way you get around this problem is to declare your arraylist as an XmlArray using the XmlArray attribute like so:

[XmlArray(ElementName="Datapoints")]
public ArrayList Datapoints;

The ArrayList also must be attributed with all the possible types it is going to store. For example, my ArrayList only stores DataPoints so I add the attribute:

[XmlArrayItem(ElementName="Dp", Type=typeof(Data.DataPoint))]

to the ArrayList and voila, it works.

My understanding it that you can actually use more than one XmlArrayItem attribute, thus allowing you to have more than one type of object in your ArrayList.

jeremiah's blog | 3181 reads