Wednesday, May 16, 2012

XmlSerializer to serialize a class, i want child tag names as given in a public property

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>




No comments:

Post a Comment