I am using GoogleFeed API (https://developers.google.com/feed/) to retrieve RSS feeds using this code:

    function loadAuto(){
    google.load("feeds", "1");  
    function initialize() {
        var feed = new google.feeds.Feed("http://www.automoto.sk/rss");
        feed.setNumEntries(window.localStorage.getItem("entriesNumber"));
        feed.load(function(result) {
            if (!result.error) {
                var feedlist = document.getElementById("feedAuto");
                for (var i = 0; i < result.feed.entries.length; i++) {
                    var li = document.createElement("li");
                    var entry = result.feed.entries[i];
                    var A = document.createElement("A");
                    var descriptionSettings = window.localStorage.getItem("descriptionSettings");
                    if (descriptionSettings=="true"){
                        var h3 = document.createElement("h3");
                        var p = document.createElement("p");
                        var pDate = document.createElement("p");
                        pDate.setAttribute("style","text-align: right; margin-top: 5px;");
                        var publishedDate = new Date(entry.publishedDate);
                        publishedDateConverted = convertTime(publishedDate);
                        pDate.appendChild(document.createTextNode(publishedDateConverted));
                        h3.setAttribute("style","white-space: normal;")
                        h3.appendChild(document.createTextNode(entry.title));
                        p.setAttribute("style","white-space: normal;")
                        p.appendChild(document.createTextNode(entry.content));
                        A.setAttribute("href",entry.link);
                        A.appendChild(h3);
                        A.appendChild(p);
                        A.appendChild(pDate);
                        }
                    else{
                        A.setAttribute("href",entry.link);
                        A.appendChild(document.createTextNode(entry.title));
                    };
                    li.appendChild(A);
                    feedlist.appendChild(li);
                }
                $("#feedAuto").listview("refresh");
            }
        });
    }
    google.setOnLoadCallback(initialize);
};

Everything is working fine but I cant load one elemenet. This is RSS structure:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
   <title>automoto.sk</title>
   <link>http://www.automoto.sk</link>
   <description>automoto.sk</description>   
   <language>sk</language>
   <image><title>automoto.sk</title><url>http://img.automoto.sk</url><link>http: //www.automoto.sk</link></image>
   <pubDate>Thu, 13 Sep 2012 12:22:45 +0200</pubDate>
    <item>
     <title><![CDATA[Nová Kia pro_ceed: Najdynamickejší Slovák]]></title>
     <link>http://www.automoto.sk/clanok/188988/nova-kia-pro-ceed-najdynamickejsi-slovak</link>
     <pubDate>Thu, 13 Sep 2012 09:22:00 +0200</pubDate>
     <guid isPermaLink="false">5e14ddbf095fe497eaf03f9a8cd88773</guid>
     <description><![CDATA[PARÍŽ 2012    Trojdverový variant druhej generácie typu cee’d má podstatne štipľavejší dizajn ako jeho praktickejší brat.]]></description>
     <enclosure url="http://img.automoto.sk/img/20/title/1395542-img-nova-kia-pro-ceed.jpg" length="0" type="image/jpeg"></enclosure>
    </item>
</rss>

I need to load img located in enclosure but I dont know how to load enclosure url variable. Maybe changing the format to XML would do it. I have already tried to change it to XML but I couldnt get it to work. So please if you know how to load the image in JSON format or if you know how to convert initialize() function so it will be working with XML and then load img URL please post your suggestion.

PS: you can find RSS at this site http://www.automoto.sk/rss/

有帮助吗?

解决方案

I have got it to work using Mixed Format. So my code changed like this:

var feed = new google.feeds.Feed("http://www.automoto.sk/rss");
feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT);

and then I added this:

var entryImageUrl = entry.xmlNode.getElementsByTagName("enclosure")[0].getAttribute("url");

inside for cycle.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top