using UnityEngine;
using System.Collections;

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

[XmlRoot("ChapterCollection")]
public class ChapterContainer {

    [XmlArray("Chapters")]
    [XmlArrayItem("Chapter", typeof(Chapter))]
    public Chapter[] chapters;

    public static ChapterContainer Load(string xmlPath) {
        // Get the XML content
        TextAsset _xml = Resources.Load<TextAsset>(xmlPath);
        StringReader reader = new StringReader(_xml.text);

        // Deserialize the XML
        XmlSerializer serializer = new XmlSerializer(typeof(ChapterContainer));
        ChapterContainer cc = serializer.Deserialize(reader) as ChapterContainer;

        reader.Close();
        return cc;
    }

}

public class Chapter {

    [XmlAttribute("name")]
    public string name;

    [XmlAttribute("time")]
    public int time;

    [XmlArray("Sentences")]
    [XmlArrayItem("Sentence", typeof(Sentence))]
    public Sentence[] sentences;

}

public struct Sentence {

    [XmlAttribute("name")]
    public string name;

    [XmlElement("Context")]
    public string context;

    [XmlElement("Word")]
    public string word;
}
