0

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);

             });
         }
 });
1
  • Thanx Amr for the edit...Any help on this one...??? Commented Apr 7, 2011 at 9:44

1 Answer 1

1

I found some articles talking about this issue:
http://think2loud.com/reading-xml-with-jquery/
http://marcgrabanski.com/articles/jquery-makes-parsing-xml-easy
http://api.jquery.com/jQuery.parseXML/

But I didn't this before my self.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.