How can I serialize this .NET Collection item?

Posted by Pure.Krome on Stack Overflow See other posts from Stack Overflow or by Pure.Krome
Published on 2010-05-31T10:35:24Z Indexed on 2010/05/31 10:43 UTC
Read the original article Hit count: 226

Filed under:
|
|
|

Hi folks,

I'm trying to xml serialize a POCO view data class into xml. It serializes, but incorrectly generates some xml.

eg. (current result .. not the one I'm after)

<ReviewListViewData>
    <reviews>
        <review>....</review>
        ...
    </reviews>
</ReviewListViewData>

I'm trying to get (notice how I've removed the bad root node?) ...

<reviews>
    <review>....</review>
    ...
</reviews>

Class is defined as...

public class ReviewListViewData
{
    [XmlArray("reviews")]
    [XmlArrayItem("review")]
    public ReviewViewData[] Reviews { get; set; }
}

and here's a sample way it's called in an ASP.NET MVC ActionMethod :-

var reviewListViewData = GetReviewListViewData(...);
return XmlResult(reviewListViewData);  // (XmlResult referenced from MVCContrib).

anyone have any ideas, please?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET