解析GeoRSS饲料与jQuery

问题描述:

我试图使用jQuery jFeed plugin解析一个原子,GeoRSS饲料和我遇到问题提取我需要的信息。例如,我需要提取摘要元素,并且想要在HTML页面上的div中呈现内容。另外,我想从georss中提取内容:点元素,并将它们传递到Google Maps以将它们呈现为地图上的点。问题是,似乎jFeed正在剥离与GeoRSS相关的信息。例如,我可以在没有问题的情况下提取标题元素,但它似乎根本不提取摘要或geors:point元素。解析GeoRSS饲料与jQuery

以下是XML的一个片段我的工作:

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss"> 
    <title>Search Results from DataWarehouse.HRSA.gov</title> 
    <link rel="self" href="http://datawarehouse.hrsa.gov/HGDWDataWebService/HGDWDataService.aspx?service=HC&zip=20002&radius=10"/> 
    <link rel="alternate" href="http://datawarehouse.hrsa.gov/"/> 
    <author> 
    <name>HRSA Geospatial Data Warehouse</name> 
    </author> 
    <id>tag:datawarehouse.hrsa.gov,2010-04-05:/</id> 
    <updated>2010-04-05T19:25:28-05:00</updated> 
    <entry> 
    <title>Christ House</title> 
    <link href="http://www.christhouse.org" /> 
    <id>tag:datawarehouse.hrsa.gov,2010-04-05:/D388C4C6-FFA4-4091-819B-64D67DC64931</id> 
    <summary type="xhtml"> 
     <div xmlns="http://www.w3.org/1999/xhtml"> 
     <div class="vcard"> 
      <div class="fn org">Christ House</div> 
      <div class="adr"> 
      <div class="street-address">1717 Columbia Rd. N.W.</div>   <span class="locality">Washington</span>,   <span class="region">District of Columbia</span>,   <span class="postal-code">20009-2803</span> 
      </div> 
      <div class="tel">202-328-1100</div> 
     </div> 
     <div> 
      Categories:   <span class="category">Service Delivery Site</span> 
     </div> 
     </div> 
    </summary> 
    <georss:point>38.9243636363636 -77.0395636363637</georss:point> 
    <updated>2010-04-04T00:00:00-05:00</updated> 
    </entry> 
</feed>

以下是我使用jQuery代码:

$(document).ready(function() { 
    $.getFeed({ 
    //url: 'http://datawarehouse.hrsa.gov/HGDWDataWebService/HGDWDataService.aspx?service=HC&zip=20002&radius=10', 
    url: 'test.xml', 
    success: function(feed) { 
     $.each(feed.items, function(index, value) { 
      $('#rssContent').append(value.title); // Set breakpoint here 
     }); 
    } 
    }); 
});

我设置该追加行断点到rssContent div,并注意到feed.items中的对象没有我之后的属性。我做错了什么,或者是否只是不按照我想要的方式工作?

看起来像jFeed只得到一些项目。来自jFeed的来源:

... 
jQuery('item', xml).each(function() { 

    var item = new JFeedItem(); 

    item.title = jQuery(this).find('title').eq(0).text(); 
    item.link = jQuery(this).find('link').eq(0).text(); 
    item.description = jQuery(this).find('description').eq(0).text(); 
    item.updated = jQuery(this).find('pubDate').eq(0).text(); 
    item.id = jQuery(this).find('guid').eq(0).text(); 

    feed.items.push(item); 
}); 
... 

修改jFeed应该是相对简单的。检出jquery.jfeed.js中的源代码。

+0

我喜欢的是我做到了这一点,但没有奏效。原来,我引用了.pack.js版本的源代码,完全错过了这个明显的观点。很高兴你提到这个,因为我开始觉得我疯了。非常感谢你。 – senfo 2010-04-06 13:35:01

+1

我花了不少时间去挖掘插件和图书馆资源,但现在我对它感到有点舒服了,这会变得更有趣。 – Anurag 2010-04-06 17:34:53