簡體   English   中英

SyndicationFeed RSS:找不到名稱空間名為“”的元素“ channel”

[英]SyndicationFeed RSS: Element 'channel' with namespace name '' was not found

我正在嘗試將rss(xml格式)加載為數據源,但是當我嘗試將其加載到聯合供稿時,會引發錯誤:

找不到名稱空間名為“”的元素“通道”。 第1行,位置21。

這是我的代碼:

public IEnumerable<FeedItem> GetRssFeedList()
{
    XmlReader reader = XmlReader.Create(_urlRssFeed);
    SyndicationFeed feed = SyndicationFeed.Load(reader);
    var feedItems = feed.Items.Select(c=> new FeedItem { Title = c.Title.Text, Link = c.Links.FirstOrDefault().ToString(), Description = c.Summary.Text});
    return feedItems;
}

_urlRssFeed =“ http://www.educaweb.com/rss/actualidad/

我檢查了它是否是有效的RSS,它是否是: http : //validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.educaweb.com%2Frss%2Factualidad%2F

我不知道那會是什么? 提前致謝。

順便說一下,這是我的自定義提要項類:

public class FeedItem
{
    public string Title { get; set; }
    public string Link { get; set; }
    public string Description { get; set; }
}

希望可以幫到我! 謝謝!

<meta name="robots" .../>

標簽是原因。 這是我解決的方法:

private static Stream RemoveInvalidRssText(Stream stream)
{
    var text = new StreamReader(stream).ReadToEnd(); // convert stream to string
    text = Regex.Replace(text, "<meta name=\"robots\" content=\"noindex\" xmlns=\"http://www.w3.org/1999/xhtml\" />", "");
    return new MemoryStream(Encoding.UTF8.GetBytes(text)); // convert to string to stream
}

我注意到了huffingtonpost RSS feed的相同問題,例如: https : //www.huffingtonpost.com/dept/entertainment/feed

顯然,這將增加將流轉換為字符串,去除問題文本並將其轉換回流的處理時間。 因此,您需要將此步驟限制為有問題的供稿。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM