Parsing XML with jQuery... problem retrieving elements

Posted by Don on Stack Overflow See other posts from Stack Overflow or by Don
Published on 2010-03-28T20:18:50Z Indexed on 2010/03/28 20:23 UTC
Read the original article Hit count: 544

Filed under:
|
|

An XML snippet:

<results>
   <review>
      <api_detail_url>http://api.giantbomb.com/review/1/</api_detail_url>
      <game>
         <api_detail_url>http://api.giantbomb.com/game/20462/</api_detail_url>
         <id>20462</id>
         <name>SingStar</name>
      </game>
      <score>4</score>
   </review>
</results>

And here's my testing code, just to show whether data is being collected or not ('data' holds the XML):

var element;

$(data).find('review').each(function() {
    element = $(this).find('name').text();
});

alert(element); 

Now here's the problem, only this query actually returns data:

$(this).find('score').text();

The alert box in this case would pop up with '4'. These two other queries don't return anything (the alert box is blank):

$(this).find('api_detail_url').text();
$(this).find('name').text();

I've tried using jQuery selectors, like...

$(this).find('game > name').text();

...but that doesn't work, either, still get a blank alert box. Am I missing something? Testing is being done in Chrome.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about Xml