1

尝试阅读 ARSTECHNICA RSS 提要时,我不断随机收到此错误。我收到以下错误:

System.Xml.XmlException:'',十六进制值 0x10,是无效字符。第 96 行,位置 1129。

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

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

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

谢谢

4

1 回答 1

4

您可以尝试将 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);
于 2012-10-15T16:07:36.907 回答