All,
I am at wits end with this one. Spent hours going through MSDN and online
articles to try to resolve this.
XmlSerializer is including the “xsi:type” attribute when I serialize a
property that is a List<Tof derived objects.
How do I stop this from happening?
Constraints:
XmlIncludeAttributes are unfeasible as bases classes are in separate
assemblies and know nothing of the specializations.
The context is not a web service. Just trying to get a text stream of the
serialized object using the XmlSerializer.
Thanks for all of your help.
[XmlRootAttribute(“Lot”, Namespace=”
http://tempuri.org”)]
public class Car
{
}
[XmlRootAttribute(“Lot”, Namespace=”
http://tempuri.org”)]
public class HotRod: Car
{
}
[XmlRootAttribute(“Lot”, Namespace=”
http://tempuri.org”)]
public class Wagon: Car
{
}
[XmlRootAttribute(“Lot”, Namespace=”
http://tempuri.org”)]
public class ParkingLot: Lot
{
[XmlArrayAttribute(“Cars”, Namespace=”
http://tempuri.org”)]
[XmlArrayItemAttribute(“Car”, Namespace=”
http://tempuri.org”)]
public List<CarCars {get; set}
}
ParkingLot should serialize like this:
<Lot xmlns=”http://tempuri.org”>
<Cars>
<Car></Car>
<Car></Car>
</Cars>
</Lot>
/************************************************** ******/
Reality Check
Instead, I get this:
This is a bit frustrating . . . . I have tried using
XmlAttributeOverrides, XmlTypeAttributes, etc etc.
Anyone know how to do this?
/************************************************** ******/
ParkingLot serializes like this instead:
<Lot xmlns=http://tempuri.org xmlns:xsi=”theXmlSchema-instance namespace”>
<Cars>
<Car xsi:Type=”HotRod”></Car>
<Car xsi:Type=”Wagon”></Car>
</Cars>
</Lot>