I am trying to write (and later read) a log in XML format. Log in my case is a stream of events, each having a corresponding class with XML serialization-compatible declaration. A trivial case is:
public abstract class Base {
[XmlAttribute]
public string Value { get; set; }
}
public class A: Base{}
public class B: Base{}
When I create XmlSerializer, I pass typeof(A), typeof(B)
as the extraTypes
parameter. That generates
<Base xsi:type="A" Value="42"/>
<Base xsi:type="B" Value="42"/>
I'd like to see
<A Value="42"/>
<B Value="42"/>
or at least
<A xsi:type="A" Value="42"/>
instead for readability.
Is it possible to do without manually generating serialization code and nesting?
I could create an instance of XmlSerializer per class, but I am not sure later I'd be able to deserialize its output.
NOTE: I am streaming, e.g. I am writing new instances of A
or B
as soon as they arrive into existing XmlWriter
.