Question by
Bradtzilla · Jan 13, 2017 at 10:43 AM ·
xmlforeachsortingsorting order
How can i sort the player data from my xml document by score?
if (File.Exists (filepath)) {
xmlDoc.Load (filepath);
foreach(XmlElement node in xmlDoc.SelectNodes("Players/Player"))
{
Player tempPlayer = new Player();
tempPlayer.Id = int.Parse(node.GetAttribute("id"));
tempPlayer.name = node.SelectSingleNode("name").InnerText;
tempPlayer.score = int.Parse(node.SelectSingleNode("score").InnerText);
Players.Add(tempPlayer);
Debug.Log (tempPlayer.score);
displayPlayerData(tempPlayer);
}
}
Comment
Answer by Bradtzilla · Jan 13, 2017 at 01:25 PM
Solved! I did this instead:
string filepath = Application.dataPath + @"/StreamingAssets/NerfHighscore.xml";
XDocument xmlDoc = XDocument.Load(filepath);
XDocument output = new XDocument(new XElement("xml", xmlDoc.Root.Elements("Player").OrderByDescending(node => node.Element("score").Value)));
var players = output.Descendants ("Player");
foreach (var item in players)
{
playerName = item.Element ("name").Value;
playerScore = item.Element ("score").Value;
Debug.Log(playerName + "\t\t" + playerScore);
}
Your answer

Follow this Question
Related Questions
Rotate/sort around a point? 0 Answers
GameObject can be seen through panel inside a canvas. 1 Answer
Render canvas inside Sorting Group 0 Answers
Programmatically Ordering Game Objects in 2d / Hierarchy 0 Answers
Daydream App Crashes on starting 1 Answer