I have several xml files which I want do deserialize.
var serializer = new XmlSerializer(typeof(Document));
var encoding = Encoding.GetEncoding("Windows-1252");
var sr = new StreamReader(current_file, encoding, true);
var reader = XmlReader.Create(sr);
var i = (Document)serializer.Deserialize(reader);
The problem is that the files have got different encodings. "Windows-1252" and "iso-8859-1". How can I deal with both of them?
Try using a
FileStream
instead of aStreamReader
. TheXmlSerializer
internally will create anXmlTextReader
that will detect the encoding.To check which encoding is being used:
I guess this answer obtaining the xml encoding will be helpful to get encoding. When you deserialize it you can use something similar to below;