Problems handling Atom with jQuery

I have an Atom feed like this ...

<?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>

      

And jQuery code like this ...

$(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
    });
  });
});

      

But as the comments say, it doesn't find the item <title>

in <entry>

, but happily finds other things.

Does anyone know why and how to overcome this?

Greetings

+2


source to share


4 answers


You have </stitle>

instead </title>

as a closing tag. I guess that's the problem :).



+1


source


Please check this jFeed: JavaScript jQuery RSS / ATOM feed parser plugin



0


source


you have a closing tag called stitle ... (oops Alex Ciminian beat me to it ... still waking up!)

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

      

just rename it to get the second title you might need to find the entry first

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

      

0


source


no need to use Jfeed ... also i think Paul's example is just a typo ... what he means is that some browser has a problem pulling the content of this tag ... i had the same experience in Safari .. maybe a tray using eq (0)

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

      

0


source







All Articles