Coding help: How to use xml serialization

Hello,
I’ve seen that xml serialization is a very common way to save files and I want to use this because:
-System.Runtime.Serialzation.Binary.Formatters doesn’t allow to serialize on Windows Phone
-PlayerPrefs is very good but can’t be used for lists.

So let’s get to the point:
I want to save this list with xml: public List<string> Collected = new List<string>();

Could anyone help me do this or at least give me a simple example on how to save/load my list.
I’ve looked on unity wiki, google it, search everywhere but still I can’t understand the logic it uses as I am new to programming

Thank You!

There are two things you’ll need here, the creation of the xml document from the list and then the serialization of the document. I’d recommend using the XDocument and XElement classes and putting the xml file in your Resources folder.

    using System.Collections.Generic;
    using System.Xml.Linq;

    //How to create and populate a new xml document from a list
    XDocument doc = new XDocument();
    doc.Add(new XElement("Items"));
    foreach (string item in Collected)
    {
        doc.Element("Items").Add(new XElement("Item", item));
    }

This will give you an xml document with the following format:

<?xml version="1.0" encoding="utf-8"?>
<Items>
    <Item>CollectedValue1</Item>
    <Item>CollectedValue2</Item>
    <Item>CollectedValue3</Item>
    <Item>CollectedValue4</Item>
...
</Items>

And finally, once you have your xml structured you can read and write it to a file as you like:

    //This is how you load a xml document from your Resources folder
    TextAsset xmlText = Resources.Load("CollectedXML") as TextAsset;
    XDocument myData = XDocument.Parse(xmlText.text);

    //And this is how you write it
    myData.Save(Application.dataPath + "/Resources/CollectedXML.xml");