I am using XmlSerializer to serialize a class, which has a list of objects
as part of it.Now what is happening is, the child tag names are taking the name from the class name but what i want is it’d take the name from a public field inside child class.Please help, which xml attribute should i use to make it work.
I have this code:
SessionAnalyser sa = new SessionAnalyser();
Circle c = new Circle();
c.Name = "AP";// I want this property as the TAG Name
XML O/P i am getting:
<SessionAnalyser>
<Circle>
<Name>AP</Name>
...
</Circle>
</SessionAnalyser>
Required XML O/P:
<SessionAnalyser>
<AP>
...
</AP>
</SessionAnalyser>
XmlSerializerdoes not support that, note least because it would have no way of deserializing it since it can’t know that.Namemaps to the AP in<AP>in advance.To do that with
XmlSerializeryou would have to implementIXmlSerializable, which is a lot of work; however, I suspect using something like a DOM (XElement, for example) would be much easier at that point.TL;DR; version