开发者

Help Needed With XML Serializer Error

here is my code

// Read the data from the file 
XmlSerializer serializer = new XmlSerializer(typeof(HighS开发者_如何学GocoreData)); 
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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜