我在尝试阅读ARSTECHNICA RSS Feed时随机收到此错误。我收到以下错误:
System.Xml.XmlException:'',十六进制值0x10,无效 字符。第96行,第1129行。
我知道这是因为XML中的charatercs无效,需要将其删除。我确实看了this删除无效的字符。
XmlReader readXML;
readXML = XmlReader.Create(URL);
SyndicationFeed News= SyndicationFeed.Load(readXML);
readXML.Close();
return News;
我不确定如何从RSS源中删除无效字符。有什么建议?
由于
答案 0 :(得分:4)
您可以尝试将rss Feed作为字符串加载,删除无效字符并加载为新闻Feed。希望有所帮助:
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);