I'm trying to read an XML file which has some Chinese characters in it. While writing the information in the file, encoding UTF-8 works properly and Chinese characters are written in the file properly. But when I try to read it it shows some ????? instead.
I'm just wondering if there is anyone who has already encountered whit this problem and can give me some clue.
First, please make sure the data is actually readable in UTF8, the way you do this is:
If you see the same garbled text, you did not actually create UTF8 encoded xml, but something else.
Back to your question:
Since you don't give us a lot of info how you parse the XML in the first place here is an example of how you would specifically parse it with UTF8:
var xmlDoc = XDocument.Parse(
File.ReadAllText("filelocation", System.Text.Encoding.UTF8));
The XDocument
class is part for the System.Xml.Linq
namespace.
Also if you want to optimize this you might not want pass in a stream rather than the string containing the entire xml document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With