Cherry
Cherry

Reputation: 33618

How read item tag with rome rss?

Consider response sample from rss url:

<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
                                           xmlns:content="http://purl.org/rss/1.0/modules/content/"
                                           xmlns:wfw="http://wellformedweb.org/CommentAPI/"
                                           xmlns:dc="http://purl.org/dc/elements/1.1/"
                                           xmlns:atom="http://www.w3.org/2005/Atom"
                                           xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
                                           xmlns:slash="http://purl.org/rss/1.0/modules/slash/">

    <channel>
        <title>MyTitle</title>
        <atom:link href="/mylink/" rel="self" type="application/rss+xml" />
        <link>somelink</link>
        <description></description>
        <lastBuildDate>Wed, 30 Jan 2019 14:00:03 +0000</lastBuildDate>
        <language>en-US</language>
        <sy:updatePeriod>hourly</sy:updatePeriod>
        <sy:updateFrequency>1</sy:updateFrequency>
        <generator>https://wordpress.org/?v=5.0.3</generator>
        <item>
            <title>item title</title>
            <link>/oitem-link</link>
            <pubDate>Wed, 30 Jan 2019 14:00:03 +0000</pubDate>
            <dc:creator><![CDATA[John]]></dc:creator>
            <category><![CDATA[Category1]]></category>
            <category><![CDATA[Amazon]]></category>
            <category><![CDATA[cleaning]]></category>
            <category><![CDATA[online shopping]]></category>
            <category><![CDATA[selling]]></category>

            <guid isPermaLink="false">/premalink</guid>
            <description><![CDATA[content]]></content:encoded>
        </item>
    </channel>
</rss>

I interested to read some tage from <item> tag. How to that with rss rome library? They sugest:

import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;

        // fetch data from URL
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = null;
    BufferedReader reader; // erader readed from http response body
    feed = input.build(reader);

But feed object does not have any API to get items collection. (or this collection is placed so deep...)

Any work arounds?

P.S. yes I can parse this via any xml (Jaxb?) parser or event with regexp or xpath. But the question is about rome library solution.

Upvotes: 1

Views: 965

Answers (1)

janih
janih

Reputation: 2234

At Rome v1.9.0 API documentation of com.rometools.rome.feed.synd.SyndFeed there is a method to get entries/items: List<SyndEntry> getEntries();

Upvotes: 0

Related Questions