Reputation: 24325
Does anyone know why the namespace is still being added to the root during datacontractserialization?
XML:
<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Event>
<Address>
.
.
.
</Response>
Code:
[DataContract(Name = "Response", Namespace = "")]
public class ApiEventResponse
{
[DataMember(EmitDefaultValue = false)]
public ApiEvent Event { get; set; }
}
var serializer = new DataContractSerializer(type, "Response", "");
return Task.Factory.StartNew(() =>
{
using (var xmlw = new XmlTextWriter(writeStream, Encoding))
{
xmlw.Formatting = Formatting.Indented;
serializer.WriteObject(xmlw, value);
}
});
Upvotes: 1
Views: 645
Reputation: 36092
The XMLSchema-instance namespace appears to be emitted regardless of what data contracts or actual namespaces are used. The XMLSchema-instance namespace prefix isn't actually used in your example, it's just declared.
The serializer is probably just emitting that namespace always in case it later discovers a situation where it needs to reference XMLSchema while serializing your data.
Upvotes: 2