The following example gives me "[One xmlns=''] was not expected." exception
public abstract class BaseClass{ }
[XmlRoot("One")]
public class ChildOne : BaseClass {}
[XmlRoot("Two")]
public class ChildTwo : BaseClass { }
class Program
{
private static void Main(string[] args)
{
var ser = new XmlSerializer(typeof (BaseClass), new Type[] {typeof (ChildOne), typeof (ChildTwo)});
var obj1 = ser.Deserialize(new StringReader(@"<?xml version=""1.0""?><One></One>"));
var obj2 = ser.Deserialize(new StringReader(@"<?xml version=""1.0""?><Two></Two>"));
}
}
I need to deserialize XML (generated not by me). Root tag may have different names which I have to map to different classes.
PS. I know there is a lot of questions like this around. I have studied them but my problem is still not solved.