To create XML text data through serialization, perform the following steps:
- Create a C# PlayerScore script class:
using System.Xml.Serialization; [System.Serializable] public class PlayerScore { [XmlElement("Name")] public string name; [XmlElement("Score")] public int score; [XmlElement("Version")] public string version; }
- Create a C# PlayerScoreCollection scrip class:
using System.Xml.Serialization; using System.IO; [XmlRoot("PlayerScoreCollection")] public class PlayerScoreCollection { [XmlArray("PlayerScores"), XmlArrayItem("PlayerScore")] public PlayerScore[] playerScores; public void Save(string path) { var serializer = new XmlSerializer(typeof(PlayerScoreCollection)); using (var stream = new FileStream(path, ...