c# - load foreign characters from xml file using StreamReader -
am loading xml file @ same time there greek characters inside file "ναι" , when load them on data grid view table appear ���.
am using xmlreader load encoding iso-8859-7 like
public xmldocument loaddocument(string x) { xmldocument document = new xmldocument(); using (streamreader stream = new streamreader(x, encoding.getencoding("iso-8859-7"))) { document.load(stream); } return (document); }
the simplest answer here not use streamreader
@ all. let xml parser handle encoding appropriately:
public xmldocument loaddocument(string x) { xmldocument document = new xmldocument(); using (var stream = file.openread(x)) { document.load(stream); } return document; }
or use xmldocument.load(string)
:
public xmldocument loaddocument(string x) { xmldocument document = new xmldocument(); document.load(x); return document; }
the xml document should specify encoding in xml declaration if needs - , that's best source of truth.
Comments
Post a Comment