2010-04-06 86 views
0

我試圖使用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中的對象沒有我之後的屬性。我做錯了什麼,或者是否只是不按照我想要的方式工作?

回答

1

看起來像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