2009-10-17 53 views
2

我有一個Atom feed這樣的...故障解析Atom提要使用jQuery

<?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 
    }); 
    }); 
}); 

但像評論說,這不是」 t找到<entry>中的<title>元素,但很高興找到其他的東西。

任何任何想法爲什麼以及如何克服這一點?

乾杯

+1

請問如果標題是'中號5.3,聖克魯斯羣島'出現問題? – 2009-10-17 12:06:38

回答

1

你有</stitle>而不是</title>作爲結束標記。我想這就是問題:)。

+0

+1你在我之前回答了LOL ...我仍然在揉揉眼睛裏的怪物:P – Mottie 2009-10-17 13:33:32

+0

爲什麼downvote?現在:)? – 2010-12-05 18:59:36

0

已關閉標籤命名stitle ...(哎呀亞歷Ciminian打我吧......還是醒來了!)

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

只是將其重命名,還去第二個標題,你可能需要找到進入第一

alert($(this).find("entry").find("title").attr('test')); 
0

療法無需使用Jfeed ......還我想保羅例子只是一個錯字......他的意思是有些瀏覽器有問題,拉動該標記的內容.. 。我在Safari上也有相同的體驗...使用eq(0)

alert($(this).find("title").eq(0).text());