- Home /
XML AppendChild not working
Hello.
Can anyone point out what's wrong with this XML generation code? (It's only one method in a bigger class.) I have one player in the players list, but the resulting XML file consists of nothing but , even though the "Writing playerData" debug line gets fired.
function SaveXML(){
var playersPath : String = Application.dataPath + "/players/";
var document : XmlDocument = new XmlDocument();
var rootElement : XmlElement = document.CreateElement("root");
document.AppendChild(rootElement);
for (var playerData : PlayerData in players){
Debug.Log("Writing playerData");
var playerNode : XmlElement = document.CreateElement("player");
rootElement.AppendChild(playerNode);
}
var writer : XmlTextWriter = new XmlTextWriter(playersPath + "players.xml", System.Text.Encoding.Unicode);
document.WriteTo(writer);
writer.Close();
}
Comment