I'm using DataContractSerializer to serialize an object that has a property of type List and I want to control how the strings are emitted.
[DataContract(Name = "ReportData", Namespace = "")]
public class Foo
{
[DataMember]
public List<string> TrackingNumbers { get; set; }
}
When I serialize this object I get this XML:
<ReportData xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<TrackingNumbers xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:string>14735ec8-81c4-44e4-9bbe-6c661eb74e54</a:string>
</TrackingNumbers>
</ReportData>
What I would like is:
<ReportData xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<TrackingNumbers xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<TrackingNumber>14735ec8-81c4-44e4-9bbe-6c661eb74e54</TrackingNumber>
</TrackingNumbers>
</ReportData>
Is this possible with DataContractSerializer? It was trivial with XmlSerializer and XmlArrayItem but I cannot figure it out.
Also, is it possible to generate XML that does not contain any namespace declarations?
Thanks very much.