views:

143

answers:

0

This is bothersome and seemingly rare to figure out. But what I have is the need to serialize a list of objects into XML without the containing list element. For instance:

public class Book
{
    public string Name { get; set; }
} 

public class Library
{
    public List<Book> Books { get; set; }
}

I need to write it like so:

<Library>
    <Book>
       <Name>...</Name.
    </Book>
    <Book>
       <Name>...</Name.
    </Book>
    <Book>
       <Name>...</Name.
    </Book>
</Library>

Is there a way to ignore the containing element so this is possible?

Edit: Duplicate of http://stackoverflow.com/questions/314242/how-to-suppress-xml-tag-for-list-property