使用 jQuery 解析 GeoRSS Feed
我正在尝试使用 jQuery jFeed 插件 来解析 Atom,GeoRSS feed,我在提取所需信息时遇到问题。例如,我需要提取摘要元素,并且希望在 HTML 页面上的 div 中呈现内容。此外,我想从 georss:point 元素中提取内容并将它们传递到 Google 地图中以将它们呈现为地图上的点。问题是 jFeed 似乎正在删除与 GeoRSS 相关的信息。例如,我可以毫无问题地提取标题元素,但它似乎根本无法提取摘要或 georss:point 元素。
以下是我正在使用的 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 根本就没有按照我想要的方式工作?
I'm attempting to use the jQuery jFeed plugin for parsing an Atom, GeoRSS feed and I'm running into issues extracting the information I need. For example, I need to extract the summary element and I would like to render the contents in a div on my HTML page. Additionally, I'd like to extract the contents from the georss:point elements and pass them into Google Maps to render them as points on a map. The problem is that it seems jFeed is stripping out the GeoRSS-related information. For example, I can extract the title element without issues, but it seems it doesn't extract the summary or georss:point elements, at all.
Following is a snippet of the XML I'm working with:
<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>
Following is the jQuery code I'm using:
$(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
});
}
});
});
I set a breakpoint on the line that appends to the rssContent div and noticed the objects in feed.items don't have the properties I'm after. Am I doing something wrong or was jFeed simply not designed to work the way I want it to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来
jFeed
只获取了少数项目。来自 jFeed 的来源:修改 jFeed 应该相对简单。查看
jquery.jfeed.js
中的源代码。Looks like
jFeed
only gets a handful of items. From jFeed's source:Modifying jFeed should be relatively straightforward. Checkout the source code in
jquery.jfeed.js
.