XML : Unable to deserialize child element of XML to

I have an XML that I'm trying to deserialize that looks like this:

  <FormName xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">      <Name>John</Name>          <ChildElement1>              <ChildData1>123456777</ChildData1>          </ChildElement1>          <ChildElement2>              <ChildData2>123456777</ChildData2>          </ChildElement2>  </FormName>    

And I'm deserializing it like this:

  FormName form = XmlSerializationHelper.Deserialize<FormName>(xml);    

The FormName class looks like this:

  [XmlInclude(typeof(ChildElement1Class))]  public class FormName : FormNameBase  {      public FormName()      {      }  }    

Where the Base class is:

  [XmlInclude(typeof(ChildElement1BaseClass))]  [XmlInclude(typeof(ChildElement2BaseClass))]  public class FormNameBase   {      public FormNameBase()      {      }      [XmlElement("ChildElement2")]      public ChildElement2BaseClass myChildElement2{ get; set; }  }    

Where ChildElement1Class is a child of ChildElement2BaseClass

I am able to successfully deserialize ChildElement2 into ChildElement2BaseClass. But not ChildElement1. It's base class is defined as an element in FormNameBase. So basically I want the deserialize of FormName to have the element ChildElement2 as type ChildElement1Class (which I've included in the XmlInclude property in FormName). Currently it's just not including this.

I hope this description is clear enough, let me know if more info is needed.

No comments:

Post a Comment