这是我的代码:
public async void getRss(string link) {
lNews.Clear();
lNewsTemp.Clear();
HttpClient client = new HttpClient();
var rssContent = await client.GetStringAsync(link);
var rssData = from rss in XElement.Parse(rssContent).Descendants("item")
select new
{
Title = rss.Element("title").Value,
Description = rss.Element("description").Value,
Link = rss.Element("link").Value,
PubDate = rss.Element("pubDate").Value
};
foreach (var rss in rssData)
{
lNews.Add(new News
{
Title = rss.Title,
Description = rss.Description,
Link = rss.Link,
PubDate = rss.PubDate
});
lNewsTemp.Add(new News
{
Title = rss.Title,
Description = rss.Description,
Link = rss.Link,
PubDate = rss.PubDate
});
}
}
如果link = link_1 = http://vnexpress.net/rss/tin-moi-nhat.rss,代码运行良好,但是link = link_2 = http://www.thanhnien.com.vn/rss/home.rss,运行时,我有错误:
System.Xml.ni.dll中发生了'System.Xml.XmlException'类型的异常,但未在用户代码中处理
附加信息:'',十六进制值0x1F,是无效字符。第1行,第1位。
rssContent有价值(当我调试时):
"\u001f�\b\0\0\0\0\0\u0004\0�\a\u001cI�%&/m�{\u007fJ�J��t�\b�\u0013$ؐ@\u0..."
但是,link = link_2在另一个网络中运行良好。
你可以帮我解释一下,并帮我解决。
谢谢!