save xml from list of classes

I’ve been searching and searching for how to write xml from lists and it seems pretty easy as long as the list contains single elements like List. What I can’t seem to find is how to use xml with list.where the class has several elements. Is it just not possible?

Here’s an example of the type of class - nothing special, its just contains variables.

private class MyClass
{
    public int idx;
    public string name;
    public bool isDone;
}

List<MyClass> myList = new List<MyClass>;

I can’t seem to find anything that would let me save the contents of the class instances. Any clues?

 using System.Xml;
 using System.Xml.Serialization;

    [XmlRoot("MyClassCollection")]
    private class MyClass
    {
        [XmlAttribute("idx")]
        public int idx;
        [XmlAttribute("name")]
        public string name;
        [XmlAttribute("isDone")]
        public bool isDone;
    }
     
    [XmlArray("MyList")]
    [XmlArrayItem("myClasses")]
    List<MyClass> myClasses = new List<MyClass>;

Then later do the save to disk routines shown in the wiki?

There’s also VStudio examples for C# that look simpler and don’t need the tags, does this work in Unity too?

System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(myClasses.GetType());