c# - 阅读 RSS 时出错

标签 c# .net-3.5 rss

我在尝试阅读 ARSTECHNICA RSS 时不断随机收到此错误喂养。我收到以下错误:

System.Xml.XmlException: '', hexadecimal value 0x10, is an invalid character. Line 96, position 1129.

我知道这是因为 XML 中的无效字符,需要将其删除。我确实看过this用于删除无效字符。

    XmlReader readXML;
    readXML = XmlReader.Create(URL);
    SyndicationFeed News= SyndicationFeed.Load(readXML);
    readXML.Close();
    return News;

我不确定如何从 RSS 提要中删除无效字符。有什么建议么?

谢谢

最佳答案

您可以尝试将 rss 提要作为字符串加载,删除无效字符并作为新闻提要加载。希望有所帮助:

HttpWebRequest httpWebRequest =  
(HttpWebRequest)WebRequest.Create("http://feeds.arstechnica.com/arstechnica/index");
HttpWebResponse httpWebesponse = (HttpWebResponse)httpWebRequest.GetResponse();

Stream dataStream = httpWebesponse.GetResponseStream();
StreamReader streamreader = new StreamReader(dataStream, Encoding.UTF8);
 string response = streamreader.ReadToEnd();
streamreader.Close();

response = response.Replace((char)0x10, ' ');

XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(response));
reader.Read();

SyndicationFeed News = SyndicationFeed.Load(reader);

关于c# - 阅读 RSS 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12897253/

相关文章:

c# - 按自定义顺序对字符串数组进行排序

c# - 如何检查文件夹的可访问性?

c# - 如何使用带有 ODP (Oracle.DataAccess) 的 >> 准备好的查询 << 更新 CLOB 字段中的数据?

c# - 使用 C# 在 .NET Framework 3.5 中进行并行编程

c# - 词袋表示问题

xml - 如何在 expressjs 4.x 中呈现 xml/rss?

javascript - 在 javascript Google Analytics 中使用 C# 变量,变量范围

c# - 在 C# 中解析 XML 文档

python - 使用 feedparser 填充 Django DateTimeField

version-control - TFS checkin RSS 提要