Xml Serialization using xsd:type



This is what I want:



<shareParcels>
<shareParcel>
<shareholders xmlns:xsi="http://ift.tt/ra1lAU" xsi:type="individualRole">
<physicalAddress>
<addressLines>17, 4f, Crownlynn Place</addressLines>
<addressLines>New Lynn</addressLines>
<addressLines>Auckland</addressLines>
<countryCode>NZ</countryCode>
</physicalAddress>
<firstName>Lei</firstName>
<lastName>NIU</lastName>
</shareholders>
<numberOfShares>100</numberOfShares>
</shareParcel>


This is what I get:



<shareParcels>
<shareParcel>
<shareholders>
<individualRole>
<physicalAddress>
<addressLines>17, 4f, Crownlynn Place</addressLines>
<addressLines>New Lynn</addressLines>
<addressLines>Auckland</addressLines>
<countryCode>NZ</countryCode>
</physicalAddress>
<firstName>Lei</firstName>
<lastName>NIU</lastName>
</individualRole>
</shareholders>
<numberOfShares>100</numberOfShares>
</shareParcel>


This is the code I have:



public class ShareParcel {
[XmlArray("shareholders")]
[XmlArrayItem("entityOrganisationRole", typeof(EntityOrganisationRole))]
[XmlArrayItem("entityOrganisationShareholder", typeof(EntityOrganisationShareholder))]
[XmlArrayItem("individualRole", typeof(IndividualRole))]
[XmlArrayItem("disqualifiedDirector", typeof(DisqualifiedDirector))]
[XmlArrayItem("individualShareholder", typeof(IndividualShareholder))]
[XmlArrayItem("directorShareholder", typeof(DirectorShareholder))]
[XmlArrayItem("director", typeof(Director))]
public List<Role> Shareholders { get; set; }

[XmlElement("numberOfShares")]
public long NumberOfShares { get; set; }
}


I can't seem to figure out how to make the serilizer use the xsd:type attribute for inherited type of Role?


Thanks in advance,


No comments:

Post a Comment