I’m using ASP.NET MVC with XmlResult from MVCContrib.
I have an array of Xxxx objects, which I pass into XmlResult.
This gets serialized as:
<ArrayOfXxxx>
<Xxxx />
<Xxxx />
<ArrayOfXxxx>
I would like this to look like:
<Xxxxs>
<Xxxx />
<Xxxx />
<Xxxxs>
Is there a way to specify how a class gets serialized when it is part of array?
I’m already using XmlType to change the display name, is there something similar that lets you set its group name when in an array.
[XmlType(TypeName="Xxxx")]
public class SomeClass
Or, will I need to add a wrapper class for this collection?
This is possible in both ways (using a wrapper and defining
XmlRootattribute on it, or addingXmlAttributeOverridesto the serializer).I implemented this in second way:
here is an array of ints, I’m using
XmlSerializerto serialize it:the data variable (which holds serialized array):
So, insted of
ArrayOfIntwe gotintsas a root name.More about
XmlSerializer‘s constructor I used could be found here.