简体   繁体   中英

How to retrieve data from tag <content:encoded> with CDATA from RSS feed with Jsoup for android?

I want to retrieve data from an RSS feed using jsoup. I am able in all tag but I can't do It when there is content:encoded tag. please anyone help me how to get data from content:encoded tag. My feed URL is https://sambad.in/feed/ and my code is as well Document doc = Jsoup.parse(String.valueOf(response)); Elements itemElements = doc.select("item");

            for (int i = 0; i < itemElements.size(); i++) {

                Element item = itemElements.get(i);
                String title = item.child(0).text();
                String link=item.child(1).text();
                String imgUrl=extractImageUrl(item.select("description").text());
                String description = extractPostText(item.select("description").text())+"From Sambad: By Pin2";
                String fullnews=extractPostText(item.children().select("http://purl.org/rss/1.0/modules/content/encoded").text());

The selector to use will be content|encoded . To specify a namespaced tag, replace the : with a | . See the jsoup selector documentation for more examples.

Here is a live example on Try Jsoup .

A couple points to note:

  1. For RSS, you should use the XML parser instead of the (default) parser. Normally that would happen automatically if you were using Jsoup.connect(url) to load the content, as it sets the parser based on the content type. But you are bypassing that (by supplying a String input), so you need to specify it manually.
  2. The result of the content|encoded selector will be a set of Elements containing text with HTML tags (not parsed HTML elements). That's because the content in the RSS is HTML encoded (escaped). If you want it as parsed HTML, you should next use the Jsoup.parseBodyFragment(String) method on the text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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