gpt4 book ai didi

c# - 阅读 RSS 时出错

转载 作者:太空宇宙 更新时间:2023-11-03 21:54:27 24 4
gpt4 key购买 nike

我在尝试阅读 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com