I have this xml and i want to return the country ID where CountryName is = Namibia
<Countries>
- <Country>
<CountryName>Zimbabwe</CountryName>
<CountryID>1</CountryID>
</Country>
- <Country>
<CountryName>South Africa</CountryName>
<CountryID>2</CountryID>
</Country>
- <Country>
<CountryName>Namibia</CountryName>
<CountryID>3</CountryID>
</Country>
- <Country>
<CountryName>Nigeria</CountryName>
<CountryID>4</CountryID>
</Country>
</Countries>
I am using this code but it is just returning 0 , How do i make this work???
$.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);
});
}
});