2

我有一个像这样的 Atom 提要......

<?xml version="1.0"?>
<feed 
    xml:base="http://earthquake.usgs.gov/" 
    xmlns="http://www.w3.org/2005/Atom" 
    xmlns:georss="http://www.georss.org/georss">
  <updated>2009-10-12T14:47:25Z</updated>
  <title>USGS M2.5+ Earthquakes</stitle>
  <subtitle>Real-time, worldwide earthquake list for the past 7 days</subtitle>
  <link rel="self" href="/eqcenter/catalogs/7day-M2.5.xml"/>
  <link href="http://earthquake.usgs.gov/eqcenter/"/>
  <author><name>U.S. Geological Survey</name></author>
  <id>http://earthquake.usgs.gov/</id>
  <icon>/favicon.ico</icon>
  <entry>
    <id>urn:earthquake-usgs-gov:us:2009mra9</id>
    <title test='GOT IT'>M 5.3, Santa Cruz Islands</title>
    <updated>2009-10-12T12:44:40Z</updated>
    <link rel="alternate" type="text/html" href="/eqcenter/recenteqsww/Quakes/us2009mra9.php"/>
    <link rel="related" type="application/cap+xml" href="/eqcenter/catalogs/cap/us2009mra9" />
    <summary type="html"><![CDATA[<p>stuff...</p>]]></summary>
    <georss:point>-11.7295 166.3124</georss:point>
    <georss:elev>-60100</georss:elev>
    <category label="Age" term="Past day"/>
  </entry>
</feed>

像这样的jQuery代码......

$(document).ready(function(){
  $.get('data/_7day-M2.5.xml', {}, function(xml){
    $(xml).find('entry').each(function(i){
      alert($(this).find("title").text());            // DOESN'T WORK (EMPTY)
      alert($(this).find("title").attr('test'));      // DOESN'T WORK ('undefined')
      alert($(this).find("id").text());               // WORKS
      alert($(this).find("georss\\:point").text());   // WORKS
    });
  });
});

但就像评论说的那样,它没有找到 中的<title>元素<entry>,但很高兴找到其他东西。

任何人有任何想法为什么以及如何克服这个问题?

干杯

4

4 回答 4

1

你有</stitle>而不是</title>作为结束标签。我想这就是问题所在:)。

于 2009-10-17T12:24:14.753 回答
0

没有必要使用 Jfeed ......我猜 Paul 的例子只是一个错字......他的意思是一些浏览器在提取该标签的内容时遇到问题......我在 Safari 上也有同样的经历......也许是托盘使用 eq(0)

alert($(this).find("title").eq(0).text());     
于 2010-12-03T20:56:13.343 回答
0

请检查这个jFeed:JavaScript jQuery RSS/ATOM feed parser plugin

于 2009-10-17T12:20:20.237 回答
0

你有一个名为 stitle 的结束标签......(哎呀,Alex Ciminian 打败了我......还在醒来!)

<title>USGS M2.5+ Earthquakes</stitle>

只需重命名它,同样要获得第二个标题,您可能需要先找到该条目

alert($(this).find("entry").find("title").attr('test')); 
于 2009-10-17T13:29:31.573 回答