Reputation: 1
here is my code
// Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
im currently doing a saving highscore for my game. but it get an error of "there is an error in xml document (0, 0). care to help or enlighten?
Upvotes: 0
Views: 357
Reputation: 115
i have had this problem before and a byte order mark was present at the beginning of the file. Check your XML file in a hex editor and see if there are three characters at the beginning. You could simply do something like the following with your raw xml
if (xml.StartsWith(ByteOrderMarkUtf8))
{
xml = xml.Remove(0, ByteOrderMarkUtf8.Length);
}
then read that into the stream
or you could do something like this when creating your stream
byte[] bytes = Encoding.UTF8.GetBytes(xml);
MemoryStream stream = new MemoryStream(bytes);
hopefully that helps
Upvotes: 1