Rss和Javascript,解析和显示提要

Rss和Javascript,解析和显示提要,javascript,jquery,xml,rss,Javascript,Jquery,Xml,Rss,在本例中,我试图提取一个RSS提要,并将其显示在一些css设计的卡片中,有点像新闻提要,显示在我页面上的divcontainer元素中。我尝试了几个选项,如feednami、jFeed等,但都没有成功。为了更好地说明我的意思和我需要获取的信息,我在下面提供了一个代码示例,听起来似乎有一个非常简单的答案,但我还没有找到答案。我知道GoogleFeedsAPI以前在这方面是很好的,但现在已经被弃用了,这是否意味着我不应该使用它 // URL of feed to pull, and integer

在本例中,我试图提取一个RSS提要,并将其显示在一些css设计的卡片中,有点像新闻提要,显示在我页面上的divcontainer元素中。我尝试了几个选项,如feednami、jFeed等,但都没有成功。为了更好地说明我的意思和我需要获取的信息,我在下面提供了一个代码示例,听起来似乎有一个非常简单的答案,但我还没有找到答案。我知道GoogleFeedsAPI以前在这方面是很好的,但现在已经被弃用了,这是否意味着我不应该使用它

// URL of feed to pull, and integer specifying how many items to pull from that feed
var feedURL = ;
var noOfItems = 20;

// In the 2D array of items we will store [0]Title, [1]Link, [2]Description/Text, [3]Source (this will be used in a later version to specify image
// in this iteration source will always be BBC so have hardcoded image) [4]Date (displayable format) [5]Date in milliseconds to be used in a later iteration
// [6]Image path (to be calculated from source, for now i have simply hardcoded the image path for the bbc logo, but eventualy will implement an array of
// feedURLs, and a switch statement to assign each source the correct logo)
var feedItems = new Array(noOfItems);
for (var i = 0; i < feedItems.length; i++) {
  x[i] = new Array(6);
}
// ----------------------- Pull Rss Feed -------------------------------------//
// Have no idea how to implement this now, have tried jFeed, and Feednami, could get neither to work
// looked into doing it myself but came across issues with javascript ecurity and the feed needing to be from the same url



//-------------------------- Creating Card on News Feed ---------------------//
// This feature could probably be made into a function? taking input of the variables below?
// Not entirely sure how best to implement this until i know how to pull the info from the xml feed
var itemtitle;
var itemlink;
var itemtext;
var itemimage = 'img/sources/bbc.png';
var itemdate;

var itemcard;   

itemcard = '<div id=card>';
itemcard += '<img src=';

itemcard += itemimage;

itemcard += ' id=cardimg>';
itemcard += '<a href=';

itemcard += itemlink;

itemcard += ' id=cardlink><h1 id=cardhead>';

itemcard += itemtitle;

itemcard += '</h1></a>';
itemcard += '<h4 id=cardinfo>';

itemcard += itemdate;

itemcard += '</h4>';
itemcard += '<p id=cardtext>';

itemcard += itemtext;

itemcard += '</p>';
itemcard += '</div>';



$('#feedcontainer').append(itemcard);
//要提取的提要的URL,以及指定要从该提要提取多少项的整数
var feedURL=;
var noOfItems=20;
//在项目的2D数组中,我们将存储[0]标题、[1]链接、[2]说明/文本、[3]源(这将在更高版本中用于指定图像)
//在这个迭代中,源始终是BBC,所以有硬编码图像[4]日期(可显示格式)[5]日期(毫秒),以便在以后的迭代中使用
//[6]图像路径(从源代码计算,目前我只是对bbc徽标的图像路径进行了硬编码,但最终将实现一系列
//FeedURL和一个开关语句,用于为每个源分配正确的徽标)
var feedItems=新阵列(noOfItems);
对于(变量i=0;i
您只需使用jQuery即可:

$(document).ready(function () {
    $.ajax({
        type: 'GET',
        url: 'https://feeds.bbci.co.uk/news/rss.xml?edition=uk',
        crossDomain: true,
        dataType: "xml",
        success: function(data){
            console.log(data);
        }
    });
});

但是,您应该意识到您可能面临的跨域问题。

因此,这将打开提要,然后我如何将每个项目的各个方面存储在我的数组中?类似feedItems[0][0]=标题的内容;feedItems[0][1]=链接等,我也可以问一下你所说的跨域问题是什么意思,我听说这是一个问题,在这种情况下会不会是一个问题,因为我的网站自然不会与你提供的代码在bbc域上。然后如何解析提要?您可以继续使用jQuery解析XML,并在Wikipedia上阅读跨源问题。