簡體   English   中英

MVC應用程序中的Google Alerts RSS Feed

[英]Google Alerts RSS Feed in MVC application

全面披露:我是MVC應用程序的新手,因此在這里我可能做不到。 這是一個非常陡峭的學習曲線。

我的任務是開發一個MVC應用程序,該應用程序可以通過Google警報顯示RSS Feed設置。 以下是我為“毒品半身像”設置的示例警報供稿的鏈接,並且我正嘗試閱讀該警報供稿:

http://www.google.com/alerts/feeds/11811034629636691591510/10685173545303329123

如何將提要的所有“輸入”字段加載到可以在視圖中顯示的數據結構中? 嘗試使用Create()函數將URL加載到XmlReader以及使用Load()函數將XDocument加載到XDocument時遇到了問題。 我一直收到Uri的XmlException。

我將以下內容用作我的Feed數據結構:

public class FeedViewModel
{
    public FeedItem[] FeedItems { get; set; }
}
public class FeedItem
{
    public string Title { get; set; }
    public string Description { get; set; }
    public DateTime Date { get; set; }
    public string Link { get; set; }
}

我現在不擔心實際顯示,只擔心將提要數據加載到類中。 誰能幫助我或指出正確的方向?

是的,即使我不確定原因,在嘗試讀取XmlReader也可能會遇到XML異常。 您可以做的就是獲取HttpResponse http://msdn.microsoft.com/zh-CN/library/system.net.webclient(v=vs.110).aspx

   public static string HttpGet()
            {
            WebClient client = new WebClient();

            // Add a user agent header in case the  
            // requested URI contains a query.

            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

            using (Stream data = client.OpenRead("http://www.google.com/alerts/feeds/11811034629636691510/10685173545303329123"))
            {
                using (StreamReader reader = new StreamReader(data))
                {
                    string s = reader.ReadToEnd();

                }
            }
        }

現在,如果標題是動態的,則具有Xml格式的字符串。 您可以解析xml並基於Xml Elements創建標頭。

暫無
暫無

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

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