Thank you very much. Now i really know what to search for.
Here is a code snippet with the asnwer to my problems.

//by Bennie Haelen
Bennie Haelen
Hi,

You need to use "XmlInclude" to include the types of your Internal- and
Extend Data Object.

Below is an example:

using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Collections;
using System.Xml.Serialization;

namespace testserialize
{
[Serializable]
public class BaseClass
{
public BaseClass()
{
}
public int x = 5;
}

[Serializable]
public class DerivedClass : BaseClass
{
public DerivedClass()
{
}
public int y = 8;
}

public class Foo
{
public int Bar = 10;
}

/// <summary>
/// Summary description for Class1.
/// </summary>
[Serializable]
[XmlInclude(typeof(DerivedClass)), XmlInclude(typeof(BaseClass))]
public class Class1
{
static void Main(string[] args)
{
XmlTextWriter </247reference/System/Xml/XmlTextWriter.aspx> writer = null;
Class1 test = new Class1();
try
{
if (!File.Exists("test.xml"))
{
File </247reference/System/IO/File.aspx>.Create("test.xml");
}

writer = new XmlTextWriter
</247reference/System/Xml/XmlTextWriter.aspx>("test.xml", Encoding
</247reference/System/Text/Encoding.aspx>.Unicode);
writer.Formatting </247reference/System/Xml/Formatting.aspx> =
Formatting </247reference/System/Xml/Formatting.aspx>.Indented;
XmlSerializer
</247reference/System/Xml/Serialization/XmlSerializer.aspx> serializer =
new XmlSerializer
</247reference/System/Xml/Serialization/XmlSerializer.aspx>(typeof(Class1));
serializer.Serialize(writer, test);
}
catch(Exception caught)
{
Console </247reference/System/Console.aspx>.WriteLine(caught.ToString());
}
finally
{
writer.Close();
}
}

public Class1()
{
myArray = new ArrayList </247reference/System/Collections/ArrayList.aspx>();
myArray.Add(new BaseClass());
myArray.Add(new DerivedClass());
}

[XmlArrayItem(typeof(DerivedClass), ElementName="Derived")]
[XmlArrayItem(typeof(BaseClass), ElementName="Base")]
public ArrayList </247reference/System/Collections/ArrayList.aspx> myArray;
}
}


Ivan Towlson wrote:

Check out XmlArrayItemAttribute.

--
Ivan Towlson
White Carbon




===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to