2
Reply

Reading a value from XML file.

Simon

Simon

May 19 2010 12:03 PM
2.8k
I am saving a player name and his score to the XML file. XML file looks like that:

 <Player><PlayerName>gaawg</PlayerName><HighestScore>0</HighestScore></Player>


How do I read the score from this file later? I think I've tried on million times with different ways and I still can't figure this out. I was trying for example with this code:
 FileStream stream = new FileStream("Decrypted.xml", FileMode.Open, FileAccess.Read, FileShare.Read);

XmlTextReader highScore = new XmlTextReader(stream);

 
highScore.ReadStartElement("highestScore");
bestResult = highScore.ReadElementContentAsInt();

return bestResult;



but it didn't work. Please help.

Answers (2)