开发者

Help Needed With XML Serializer Error

开发者 https://www.devze.com 2023-02-10 19:54 出处:网络
here is my code // Read the data from the file XmlSerializer serializer = new XmlSerializer(typeof(HighS开发者_如何学GocoreData));

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

精彩评论

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