简体   繁体   English

使用联合从 RSS 提要获取图像?

[英]Getting an image from an RSS feed, using syndication?

I am building a Windows Phone app and using SyndicationFeed to read an RSS feed.我正在构建一个 Windows Phone 应用程序并使用SyndicationFeed阅读 RSS 提要。 How do I get the picture from the feed?我如何从提要中获取图片?

Will I need a converter(?), but I don't know what will go in it.我需要转换器吗(?),但我不知道 go 会是什么。 I saw there is an ImageUrl property and I tried putting that in use but no joy.我看到有一个ImageUrl属性,我尝试使用它但没有任何乐趣。 :( :(

The pictures need to be filtered by the category together with the feed (which is predefined).图片需要按类别与提要(预定义)一起过滤。 I know how to get the feed filtered (generous forum member helped:) ) just getting images is the problem.我知道如何过滤提要(慷慨的论坛成员帮助:))只是获取图像是问题所在。

I'm using an MSDN example as a background: http://msdn.microsoft.com/en-us/library/hh487167(v=vs.92).aspx我使用 MSDN 示例作为背景: http://msdn.microsoft.com/en-us/library/hh487167(v=vs.92).aspx

My feed: http://www.zimo.co/feed/我的饲料: http://www.zimo.co/feed/


I would use this regex to get the images from the feed:我会使用这个正则表达式从提要中获取图像:

Regex rg = new Regex(@"<img.*?src=""(.*?)""", RegexOptions.IgnoreCase);

but the problem is how to implement it.但问题是如何实施。 so I get the feed and the picture at the same time:(所以我同时得到提要和图片:(

this is the code I use:这是我使用的代码:

private void UpdateFeedList(string feedXML)
    {
        StringReader stringReader = new StringReader(feedXML);
        XmlReader xmlReader = XmlReader.Create(stringReader);
        SyndicationFeed feed = SyndicationFeed.Load(xmlReader);


Regex rg = new Regex(@"<img.*?src=""(.*?)""", RegexOptions.IgnoreCase);


        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {

ls_text.ItemsSource = feed.Items;


        });
    }

There's nothing in the RSS specification that provides for a singular image that represents the <item> being processed. RSS 规范中没有提供表示正在处理的<item>的单一图像。 If you want to have an image, you can try parsing the <content> element and pulling out one or more images from the element contents.如果你想要一张图片,你可以尝试解析<content>元素并从元素内容中提取一个或多个图像。

To get the image links out of the source, you're going to need to parse the text to get a match of all <img> tags in the text.要从源中获取图像链接,您将需要解析文本以匹配文本中的所有<img>标记。 You can try to do this in a couple ways.您可以尝试通过几种方式来做到这一点。 You could try to do a RegEx match of the img tags, or you could try to load the text into an XML document and parse it.您可以尝试对 img 标签进行 RegEx 匹配,或者您可以尝试将文本加载到 XML 文档中并进行解析。 The problem is, it's not full HTML, so you might have to modify it a bit (for example, you might have to put an enclosing set of tags around the content, if the content isn't already enclosed by <p> tags.问题是,它不是完整的 HTML,因此您可能需要对其进行一些修改(例如,如果内容尚未包含在<p>标记中,您可能需要在内容周围放置一组封闭的标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM