如何从rss feed中提取图像通用Windows应用程序实时图块

时间:2015-12-15 07:18:46

标签: c# uwp

我正在尝试从图片位于其中的http://bangla.bdnews24.com/?widgetName=rssfeed&widgetId=1151&getXmlFeed=true网址添加图片 cropimage标记。我目前正在使用以下代码行提取标题和摘要

 private static async Task<SyndicationFeed> GetMSDNBlogFeed()
    {
        SyndicationFeed feed = null;

        try
        {
            // Create a syndication client that downloads the feed.  
            SyndicationClient client = new SyndicationClient();
            client.BypassCacheOnRetrieve = true;
            client.SetRequestHeader(customHeaderName, customHeaderValue);

            // Download the feed. 
            feed = await client.RetrieveFeedAsync(new Uri(feedUrl));
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.ToString());
        }

        return feed;
    }

    private static void UpdateTile(SyndicationFeed feed)
    {
        // Create a tile update manager for the specified syndication feed.
        var updater = TileUpdateManager.CreateTileUpdaterForApplication();
        updater.EnableNotificationQueue(true);
        updater.Clear();

        // Keep track of the number feed items that get tile notifications. 
        int itemCount = 0;

        // Create a tile notification for each feed item.
        foreach (var item in feed.Items)
        {
            XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text09);

            var title = item.Title;
            var summary = item.Summary;

            if (itemCount!=0)
            {
                string titleText = title.Text == null ? String.Empty : title.Text;
                string summaryText = summary.Text == null ? String.Empty : summary.Text;


                tileXml.GetElementsByTagName(textElementName)[0].InnerText = titleText;
                tileXml.GetElementsByTagName(textElementName)[1].InnerText = summaryText;

                // Create a new tile notification. 
                updater.Update(new TileNotification(tileXml));

            }

            // Don't create more than 5 notifications.
            if (itemCount++ > 7) break;
        }
    }

    // Although most HTTP servers do not require User-Agent header, others will reject the request or return 
    // a different response if this header is missing. Use SetRequestHeader() to add custom headers. 
    static string customHeaderName = "User-Agent";
    static string customHeaderValue = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";

    static string textElementName = "text";
    static string feedUrl = @"http://bangla.bdnews24.com/?widgetName=rssfeed&widgetId=1151&getXmlFeed=true";

如何提取图像?提前致谢

1 个答案:

答案 0 :(得分:0)

您必须使用XML解析器来获取数据。我建议使用LINQ to XML