ACTUAL code and xml file
Code of program
class Program
{
static void Main(string[] args)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "file.xml";
//string path2 = @"F:\fd.xml";
FileStream fs = new FileStream(path, FileMode.Open);
XmlReader reader = XmlReader.Create(fs);
SaveGame sav = new XmlSerializer(typeof(SaveGame)).Deserialize(reader) as SaveGame;
Console.WriteLine(sav.player.friendshipData[0].key);
Console.WriteLine(sav.player.friendshipData[0].value.Points);
fs.Close();
Console.ReadKey();
}
}
public class SaveGame
{
public Player player { get; set; }
}
public class Player
{
public item[] friendshipData { get; set; }
}
public class item
{
public string key { get; set; }
public Friendship value { get; set; }
}
public class Friendship
{
public int Points {get;set;}
}
}
XML File to work with:
<SaveGame>
<player>
<friendshipData>
<item>
<key>
<string>Name1</string>
</key>
<value>
<Friendship>
<Points>324</Points>
</Friendship>
</value>
</item>
<item>
<key>
<string>Name2</string>
</key>
<value>
<Friendship>
<Points>98</Points>
</Friendship>
</value>
</item>
</friendshipData>
</player>
</SaveGame>
I tried other posts, and that's not working, cause all readen values are null.
Please, how to deserialize this document? And with explanation, please.
If i set {get;set;} to variables, it won't read next item, if i set {get;} it read every item, but every item have null value.
Just in case, i can't edit XML File for some reasons. XML File is alright.