Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: Retreving only first attribute of a specific node from XML
    primarykey
    data
    text
    <p>Basically, dealing with an XML feed that's not written in the nicest way (Youtube API data), and follows on from <a href="https://stackoverflow.com/questions/3163046/parsing-annoying-youtube-api-xml-feeds-with-jquery">a previous question on the topic</a>.</p> <p>Currently, there are four nodes in the file named <code>media:thumbnail</code>. Each <code>media.thumbnail</code> node has various attributes, one of which is <code>url</code>. I am only wanting to retrieve value of the first occurrence of the <code>url</code> attribute (the result being <code>http://i.ytimg.com/vi/CQP_AuT4zXQ/2.jpg</code>).</p> <p>Example;</p> <pre><code>&lt;item&gt; ... &lt;media:group&gt; ... &lt;media:thumbnail url='http://i.ytimg.com/vi/CQP_AuT4zXQ/2.jpg' height='90' width='120' time='00:04:53.500'/&gt; &lt;media:thumbnail url='http://i.ytimg.com/vi/CQP_AuT4zXQ/1.jpg' height='90' width='120' time='00:02:26.750'/&gt; &lt;media:thumbnail url='http://i.ytimg.com/vi/CQP_AuT4zXQ/3.jpg' height='90' width='120' time='00:07:20.250'/&gt; &lt;media:thumbnail url='http://i.ytimg.com/vi/CQP_AuT4zXQ/0.jpg' height='240' width='320' time='00:04:53.500'/&gt; ... &lt;/media:group&gt; ... &lt;/item&gt; </code></pre> <p>My knowledge of jQuery is still developing, and I've been able to retrieve the values of the <code>url</code> attribute for all occurrences of <code>media:thumbnail</code> using the following code:</p> <pre><code>$(this).find("[nodeName=media:thumbnail]").each(function() { $("#output").append("&lt;img src=\"" + $(this).attr("url") + "\"&gt;\n"); }); </code></pre> <p>How do I now limit this so I only grab the value of <code>url</code> for the first occurrence of <code>media:thumbnail</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload