HOow do i loop through a returned xml object in jquery
<p>I have this xml and i want to return the country ID where CountryName is = Namibia</p>

<pre><code> &lt;Countries&gt;
- &lt;Country&gt;
  &lt;CountryName&gt;Zimbabwe&lt;/CountryName&gt; 
  &lt;CountryID&gt;1&lt;/CountryID&gt; 
  &lt;/Country&gt;
- &lt;Country&gt;
  &lt;CountryName&gt;South Africa&lt;/CountryName&gt; 
  &lt;CountryID&gt;2&lt;/CountryID&gt; 
  &lt;/Country&gt;
- &lt;Country&gt;
  &lt;CountryName&gt;Namibia&lt;/CountryName&gt; 
  &lt;CountryID&gt;3&lt;/CountryID&gt; 
  &lt;/Country&gt;
- &lt;Country&gt;
  &lt;CountryName&gt;Nigeria&lt;/CountryName&gt; 
  &lt;CountryID&gt;4&lt;/CountryID&gt; 
  &lt;/Country&gt;
&lt;/Countries&gt;
</code></pre>

<p>I am using this code but it is just returning 0 , How do i make this work???</p>

<pre><code>$.ajax({
        type:"GET",
        url : "countriesxml.php",
        dataType: "xml",
        success: function(xml){
            $(xml).find("Country").each(function(){
                var cid = 0;
                if($(this).find("CountryName").text()==cname)
                {
                    cid = $(this).find("CountryID").text();

                 }
                 else
                 {
                    cid = 0;
                 }
                 alert(cid);

             });
         }
 });
</code></pre>
