c#xml特殊字符编码

c#xml特殊字符编码,c#,asp.net,character-encoding,C#,Asp.net,Character Encoding,我想加载xml文档,但有一些特殊符号,如:ąęėįųū,在给定的编码中,我得到了错误无效字符。问题是如何在加载xml之前对这些字符进行编码 // load xml result from Google weather XDocument xd = XDocument.Load("http://www.google.com/ig/api?weather=vilnius&hl=ru"); 问题在于编码。如果您使用StreamReader,它应该检测响应的编码,然后允许您调用XDocumen

我想加载xml文档,但有一些特殊符号,如:
ąęėįųū
,在给定的编码中,我得到了错误
无效字符。
问题是如何在加载xml之前对这些字符进行编码

// load xml result from Google weather
XDocument xd = XDocument.Load("http://www.google.com/ig/api?weather=vilnius&hl=ru");
问题在于编码。如果您使用StreamReader,它应该检测响应的编码,然后允许您调用XDocument.Load


问题在于编码。如果您使用StreamReader,它应该检测响应的编码,然后允许您调用XDocument.Load。

我会尝试一下

WebClient cln = new WebClient();
var str = cln.DownloadString("http://www.google.com/ig/api?weather=vilnius&hl=ru");
XDocument xDoc = XDocument.Load(new StringReader(str));

我想试试这个

WebClient cln = new WebClient();
var str = cln.DownloadString("http://www.google.com/ig/api?weather=vilnius&hl=ru");
XDocument xDoc = XDocument.Load(new StringReader(str));

对不起,我不明白你想要什么。上面的编辑应该可以。对不起,我不明白你想要什么。上面的编辑应该可以工作。