How do I add an image to an item in RSS 2.0?

后端 未结 9 847
青春惊慌失措
青春惊慌失措 2021-02-03 23:50

Is there a way to send only an Image with a link and some alt text for each item in an RSS feed?

I looked at the enclosure tag but this is only for videos

相关标签:
9条回答
  • 2021-02-04 00:34

    Regarding the <p> tag issue, You need to encode html within the xml.

    Your code would look something like this:

    <description>&lt;p&gt; Text in the tag &lt;/p&gt;</description>
    
    0 讨论(0)
  • 2021-02-04 00:35

    You should use the enclosure tag within item to include the image. You can use it for images by setting the correct Mime Type (for example: image/jpeg) and including the image size as the "length" attribute. The length attribute doesn't need to be completely accurate but it's required for the RSS to be considered valid.

    Here's a helpful article that discusses this and other options.

    0 讨论(0)
  • 2021-02-04 00:35

    Example in Rome tools (https://rometools.github.io/rome/)

    Item item = new Item();
    
    Enclosure enclosure = new Enclosure();
    
    String imageUrl = "...";
    enclosure.setUrl(imageUrl);
    
    // set corect image type
    enclosure.setType("image/jpeg");
    
    List<Enclosure> enclosureList = List.of(enclosure);
    
    item.setEnclosures(enclosureList);
    
    0 讨论(0)
提交回复
热议问题