How can I use a list inside a XML Serializer class?

I am trying to work with XML Serializer now since it seems more flexible than XMLTextReaders are. I’m trying to use it to create a tree that contains multiple elements of the same type that would ideally look something like this.

<library>Red
 <book>Hobbit</book>
 <book>Xenocide</book>
</library>
<library>Blue
 <book>Hyperion</book>
 <book>Endymion</book>
</library>

I have tried using a list to declare the class that serializes the xml file but I can’t see to get it to work, I’d rather not have to use an array if I can avoid it because I it doesn’t have that nice dynamic quality like a list. Currently my code looks like this.

public class library{ 
public List<Books> book; 
}
public class Books{ 
public string Book;  
}

If anyone can help me I’d greatly appreciate it. I’m having a pretty hard time wrapping my head around the XML Serializer. Thanks.

edit: Sorry for all the revisions I had to work to get the formatting to display correctly.

Your XML output file would probably look more like this:

<library>
    <book>
        <Book>Blah</Book>
    </book>
</library>

You would need to use it like this (untested):

Library library = new Library();
library.books.Add(new Book());

XmlSerializer serializer = new XmlSerializer(typeof(Library));
TextWriter textWriter = new StreamWriter(Application.dataPath + "Resources");
serializer.Serialize(textWriter, library);
textWriter.Close();

Here are the class definitions:

[XmlRoot("Library")]
[XmlInclude(typeof(Book))]
public class Library {
    [XmlArray("Library")]
    [XmlArrayItem("Book")]
    public List<Book> books;
}

[XmlType("Book")]
public class Book {
    [XmlElement("Name")]
    public string name;
}